Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2013 - 2015, Neemworks Nigeria <dev@nimworks.com>
  Permission to use, copy, modify, and distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.
 
  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
package nw.commons.util;
Utility operations spawning threads

Author(s):
kulgan
public class AsyncFactory extends NeemClazz{

Parameters:
proc instance of runnable to execute as thread
processName name of process
autoStart should thread be started automatically
daemon should the report run as a daemon
	public static void spawnRunnable(Runnable procString processNameboolean autoStartboolean daemon){
		Thread t = new Thread(proc);
		t.setName(processName);
		if(daemon)
			t.setDaemon(daemon);
		if(autoStart)
			t.start();
	}

Spawn a single thread

Parameters:
proc Runnable class to spawn
processName process name used to identify this thread
	public static void spawnRunnable(Runnable procString processName){
		spawnRunnable(procprocessNametruefalse);
	}

Parameters:
clazz must have a default constructor
processName unique name for the thread
numberOfProcess number of threads to spawn
	public static void spawnMultiple(Class<?> clazzString processNameint numberOfProcess){
		for(int z = 0; z <= numberOfProcessz++){
			try {
				spawnRunnable(procprocessName + "_" + z);
catch (Exception e) {
				se(AsyncFactory.class""e);
			}
		}
	}
New to GrepCode? Check out our FAQ X