List of usage examples for java.lang Thread setPriority
public final void setPriority(int newPriority)
From source file:com.autodomum.example.Example1.java
public static void main(String[] args) throws Exception { final ConfigurableApplicationContext context = SpringApplication.run(Example1.class, args); final JsonLampDao jsonLampDao = context.getBean(JsonLampDao.class); final EventComponent eventComponent = context.getBean(EventComponent.class); final EventContext eventContext = context.getBean(EventContext.class); final TelldusComponent telldusComponent = context.getBean(TelldusComponent.class); final NashornScriptComponent nashornScriptComponent = context.getBean(NashornScriptComponent.class); final Thread eventComponentThread = new Thread(eventComponent); eventComponentThread.setDaemon(true); eventComponentThread.setPriority(Thread.MIN_PRIORITY); eventComponentThread.setName("EventComponent"); eventComponentThread.start();/*from w ww . j a v a 2 s .c om*/ // Coordinates of Stockholm eventContext.setCoordinate(new Coordinate(18.063240d, 59.334591d)); eventComponent.updateEventContext(); eventComponent.register(LampStateChangedEvent.class, telldusComponent); final Thread telldusComponentThread = new Thread(telldusComponent); telldusComponentThread.setDaemon(true); telldusComponentThread.setPriority(Thread.MIN_PRIORITY); telldusComponentThread.setName("Telldus"); telldusComponentThread.start(); try (InputStream inputStream = Example1.class.getResourceAsStream("/lamps.json")) { jsonLampDao.load(inputStream); } try (InputStream inputStream = Example1.class.getResourceAsStream("/ai.js")) { nashornScriptComponent.replaceScript(inputStream); } }
From source file:Main.java
public static void main(String[] args) { Thread t = Thread.currentThread(); System.out.println("main Thread Priority:" + t.getPriority()); Thread t1 = new Thread(); System.out.println("Thread(t1) Priority:" + t1.getPriority()); t.setPriority(Thread.MAX_PRIORITY); System.out.println("main Thread Priority:" + t.getPriority()); Thread t2 = new Thread(); System.out.println("Thread(t2) Priority:" + t2.getPriority()); // Change thread t2 priority to minimum t2.setPriority(Thread.MIN_PRIORITY); System.out.println("Thread(t2) Priority:" + t2.getPriority()); }
From source file:ObjectFIFOTest.java
public static void main(String[] args) { final ObjectFIFO fifo = new ObjectFIFO(5); Runnable fullCheckRunnable = new Runnable() { public void run() { fullCheck(fifo);/*from w w w. jav a 2 s .c om*/ } }; Thread fullCheckThread = new Thread(fullCheckRunnable, "fchk"); fullCheckThread.setPriority(9); fullCheckThread.setDaemon(true); // die automatically fullCheckThread.start(); Runnable emptyCheckRunnable = new Runnable() { public void run() { emptyCheck(fifo); } }; Thread emptyCheckThread = new Thread(emptyCheckRunnable, "echk"); emptyCheckThread.setPriority(8); emptyCheckThread.setDaemon(true); // die automatically emptyCheckThread.start(); Runnable consumerRunnable = new Runnable() { public void run() { consumer(fifo); } }; Thread consumerThread = new Thread(consumerRunnable, "cons"); consumerThread.setPriority(7); consumerThread.start(); Runnable producerRunnable = new Runnable() { public void run() { producer(fifo); } }; Thread producerThread = new Thread(producerRunnable, "prod"); producerThread.setPriority(6); producerThread.start(); }
From source file:ThreadDemo.java
/** * This main method creates and starts two threads in addition to the initial * thread that the interpreter creates to invoke the main() method. *//* w ww . j a v a 2 s.c om*/ public static void main(String[] args) { // Create the first thread: an instance of this class. Its body is // the run() method above ThreadDemo thread1 = new ThreadDemo(); // Create the second thread by passing a Runnable object to the // Thread() construtor. The body of this thread is the run() method // of the anonymous Runnable object below. Thread thread2 = new Thread(new Runnable() { public void run() { for (int i = 0; i < 5; i++) compute(); } }); // Set the priorities of these two threads, if any are specified if (args.length >= 1) thread1.setPriority(Integer.parseInt(args[0])); if (args.length >= 2) thread2.setPriority(Integer.parseInt(args[1])); // Start the two threads running thread1.start(); thread2.start(); // This main() method is run by the initial thread created by the // Java interpreter. Now that thread does some stuff, too. for (int i = 0; i < 5; i++) compute(); // We could wait for the threads to stop running with these lines // But they aren't necessary here, so we don't bother. // try { // thread1.join(); // thread2.join(); // } catch (InterruptedException e) {} // The Java VM exits only when the main() method returns, and when all // threads stop running (except for daemon threads--see setDaemon()). }
From source file:ffx.numerics.fft.RowMajorComplex3DCuda.java
/** * <p>//from www.j a v a2 s . com * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[2]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { int index = RowMajorComplex3D.iComplex3D(x, y, z, dim, dim); orig[index / 2] = random.nextDouble(); recip[index / 2] = orig[index / 2]; } } } RowMajorComplex3D complex3D = new RowMajorComplex3D(dim, dim, dim); RowMajorComplex3DParallel complex3DParallel = new RowMajorComplex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); RowMajorComplex3DCuda complex3DCUDA = new RowMajorComplex3DCuda(dim, dim, dim, data, recip); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } complex3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DCUDA.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs((answer[i] - data[2 * i]) / dimCubed); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:org.geotools.utils.coveragetiler.CoverageTiler.java
/** * @param args//from w ww . j av a2s .c o m * @throws MalformedURLException * @throws InterruptedException */ public static void main(String[] args) throws MalformedURLException, InterruptedException { final CoverageTiler coverageTiler = new CoverageTiler(); coverageTiler.addProcessingEventListener(coverageTiler); if (coverageTiler.parseArgs(args)) { final Thread t = new Thread(coverageTiler, NAME); t.setPriority(coverageTiler.getPriority()); t.start(); try { t.join(); } catch (InterruptedException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } else LOGGER.fine("Exiting..."); }
From source file:ffx.numerics.fft.Real3DCuda.java
/** * <p>/*from w w w . ja v a2 s. co m*/ * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[1]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } if (dimNotFinal % 2 != 0) { dimNotFinal++; } final int dim = dimNotFinal; System.out.println(String.format( "Initializing a %d cubed grid.\n" + "The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; final int dimCubed2 = (dim + 2) * dim * dim; /** * Create an array to save the initial input and result. */ final double orig[] = new double[dimCubed2]; final double answer[] = new double[dimCubed2]; final double data[] = new double[dimCubed2]; final double recip[] = new double[dimCubed]; final float origf[] = new float[dimCubed2]; final float dataf[] = new float[dimCubed2]; final float recipf[] = new float[dimCubed]; Random randomNumberGenerator = new Random(1); int index = 0; int index2 = 0; /** * Row-major order. */ for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { float randomNumber = randomNumberGenerator.nextFloat(); orig[index] = randomNumber; origf[index] = randomNumber; index++; recip[index2] = 1.0; recipf[index2] = 1.0f; index2++; } // Padding index += 2; } } Real3D real3D = new Real3D(dim, dim, dim); Real3DParallel real3DParallel = new Real3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); Real3DCuda real3DCUDA = new Real3DCuda(dim, dim, dim, dataf, recipf); Thread cudaThread = new Thread(real3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; real3D.setRecip(recip); for (int i = 0; i < reps; i++) { System.arraycopy(orig, 0, data, 0, dimCubed2); long time = System.nanoTime(); real3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format("%2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } System.arraycopy(data, 0, answer, 0, dimCubed2); real3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { System.arraycopy(orig, 0, data, 0, dimCubed2); long time = System.nanoTime(); real3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format("%2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; index = 0; for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { double error = Math.abs((orig[index] - data[index] / dimCubed)); if (error > maxError) { maxError = error; } rmse += error * error; index++; } index += 2; } } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format("Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { System.arraycopy(origf, 0, dataf, 0, dimCubed2); long time = System.nanoTime(); real3DCUDA.convolution(dataf); time = (System.nanoTime() - time); System.out.println(String.format("%2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } real3DCUDA.free(); real3DCUDA = null; maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; index = 0; for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { if (Float.isNaN(dataf[index])) { logger.info(String.format("Not a number %d %d %d", x, y, z)); System.exit(-1); } double error = Math.abs(origf[index] - dataf[index]); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; index++; } index += 2; } } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format("CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); System.out.println(String.format("Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format("Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format("Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format("Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format("CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:ffx.numerics.fft.Complex3DCuda.java
/** * <p>//ww w.j a v a 2 s. co m * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[1]); if (reps < 1) { reps = 10; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); int index = 0; for (int k = 0; k < dim; k++) { for (int j = 0; j < dim; j++) { for (int i = 0; i < dim; i++) { orig[index] = random.nextDouble(); //recip[index] = orig[index]; recip[index] = 1.0; index++; } } } Complex3D complex3D = new Complex3D(dim, dim, dim); Complex3DParallel complex3DParallel = new Complex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); complex3DParallel.setRecip(recip); Complex3DCuda complex3DCUDA = new Complex3DCuda(dim, dim, dim); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); complex3DCUDA.setRecip(recip); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); //complex3D.convolution(data); complex3D.fft(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); //complex3DParallel.convolution(data); complex3DParallel.fft(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); DoubleBuffer cudaBuffer = complex3DCUDA.getDoubleBuffer(); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { // data[j * 2] = orig[j]; // data[j * 2 + 1] = 0.0; cudaBuffer.put(j * 2, orig[j]); cudaBuffer.put(j * 2 + 1, 0.0); } long time = System.nanoTime(); //complex3DCUDA.convolution(data); complex3DCUDA.fft(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - cudaBuffer.get(2 * i)); // double error = Math.abs(answer[i] / dimCubed - data[2 * i]); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:org.geotools.utils.imagepyramid.PyramidBuilder.java
/** * This tool is designed to be used by the command line using this main * class but it can also be used from an GUI by using the setters and * getters./*from ww w . j a v a 2 s. c o m*/ * * @param args * @throws IOException * @throws IllegalArgumentException * @throws InterruptedException */ public static void main(String[] args) throws IllegalArgumentException, IOException, InterruptedException { // creating an overviews embedder final PyramidBuilder builder = new PyramidBuilder(); // adding the embedder itself as a listener builder.addProcessingEventListener(builder); // parsing input argumentBuilder if (builder.parseArgs(args)) { // creating a thread to execute the request process, with the // provided priority final Thread t = new Thread(builder, "PyramidBuilder"); t.setPriority(builder.getPriority()); t.start(); try { t.join(); } catch (InterruptedException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } else if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Unable to parse command line argumentBuilder, exiting..."); }
From source file:org.geotools.utils.imagepyramid.PyramidLayerBuilder.java
/** * /*from w ww . j a v a 2 s.c om*/ * @param args * @throws IOException * @throws IllegalArgumentException * @throws InterruptedException */ public static void main(String[] args) throws IllegalArgumentException, IOException, InterruptedException { final PyramidLayerBuilder pyramidBuilder = new PyramidLayerBuilder(); pyramidBuilder.addProcessingEventListener(pyramidBuilder); if (pyramidBuilder.parseArgs(args)) { final Thread t = new Thread(pyramidBuilder, "PyramidBuilder"); t.setPriority(pyramidBuilder.getPriority()); t.start(); try { t.join(); } catch (InterruptedException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } } else LOGGER.fine("Exiting..."); }