本文整理汇总了Java中java.util.concurrent.ForkJoinPool.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java ForkJoinPool.shutdown方法的具体用法?Java ForkJoinPool.shutdown怎么用?Java ForkJoinPool.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ForkJoinPool
的用法示例。
在下文中一共展示了ForkJoinPool.shutdown方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
public void execute()
{
finished = new CountDownLatch(Width * Height);
ForkJoinPool pool = new ForkJoinPool(
nThreads,
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
(t,e) -> e.printStackTrace(),
false);
for (Cell cell : cells) {
pool.execute(cell.neighbors[0]);
}
try {
finished.await();
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
pool.shutdown();
}
示例2: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Usage: NQueensCS [minBoardSize=N] [maxBoardSize=N] [procs=N] [reps=N]
*/
public static void main(String[] args) throws Exception {
// Board sizes too small: hard to measure well.
// Board sizes too large: take too long to run.
final int minBoardSize = intArg(args, "minBoardSize", 8);
final int maxBoardSize = intArg(args, "maxBoardSize", 15);
final int procs = intArg(args, "procs", 0);
for (int reps = intArg(args, "reps", 10); reps > 0; reps--) {
ForkJoinPool g = (procs == 0) ?
new ForkJoinPool() :
new ForkJoinPool(procs);
lastStealCount = g.getStealCount();
for (int i = minBoardSize; i <= maxBoardSize; i++)
test(g, i);
System.out.println(g);
g.shutdown();
}
}
示例3: testAwaitTermination_timesOut
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* awaitTermination on a non-shutdown pool times out
*/
public void testAwaitTermination_timesOut() throws InterruptedException {
ForkJoinPool p = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(p)) {
assertFalse(p.isTerminated());
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
assertFalse(p.awaitTermination(-1L, NANOSECONDS));
assertFalse(p.awaitTermination(-1L, MILLISECONDS));
assertFalse(p.awaitTermination(randomExpiredTimeout(),
randomTimeUnit()));
long timeoutNanos = 999999L;
long startTime = System.nanoTime();
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
assertTrue(System.nanoTime() - startTime >= timeoutNanos);
assertFalse(p.isTerminated());
startTime = System.nanoTime();
long timeoutMillis = timeoutMillis();
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
assertFalse(p.isTerminated());
p.shutdown();
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
assertTrue(p.isTerminated());
}
}
示例4: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/*
* Create an array of 10000 elements
*/
int array[]=new int[10000];
/*
* ForkJoinPool to execute the task
*/
ForkJoinPool pool=new ForkJoinPool();
/*
* Task to increment the elements of the array
*/
Task task=new Task("Task",array,0,array.length);
/*
* Send the task to the pool
*/
pool.invoke(task);
/*
* Shutdown the pool
*/
pool.shutdown();
/*
* Write a message in the console
*/
System.out.printf("Main: End of the program.\n");
}
示例5: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Main method of the example
* @param args
*/
public static void main(String[] args) {
// Creates a task
OneSecondLongTask task=new OneSecondLongTask();
// Creates a new Handler
Handler handler = new Handler();
// Creates a Factory
AlwaysThrowsExceptionWorkerThreadFactory factory=new AlwaysThrowsExceptionWorkerThreadFactory();
// Creates a new ForkJoinPool
ForkJoinPool pool=new ForkJoinPool(2,factory,handler,false);
// Execute the task in the pool
pool.execute(task);
// Shutdown the pool
pool.shutdown();
// Wait for the finalization of the tasks
try {
pool.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.printf("Main: The program has finished.\n");
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:33,代码来源:Main.java
示例6: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Main method of the class
*/
public static void main(String[] args) {
// Array of 100 integers
int array[]=new int[100];
// Task to process the array
Task task=new Task(array,0,100);
// ForkJoinPool to execute the Task
ForkJoinPool pool=new ForkJoinPool();
// Execute the task
pool.execute(task);
// Shutdown the ForkJoinPool
pool.shutdown();
// Wait for the finalization of the task
try {
pool.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Check if the task has thrown an Exception. If it's the case, write it
// to the console
if (task.isCompletedAbnormally()) {
System.out.printf("Main: An exception has ocurred\n");
System.out.printf("Main: %s\n",task.getException());
}
System.out.printf("Main: Result: %d",task.join());
}
示例7: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Usage: Integrate [procs=N] [reps=N] forkPolicy=serial|dynamic|fork
*/
public static void main(String[] args) throws Exception {
final int procs = intArg(args, "procs",
Runtime.getRuntime().availableProcessors());
final int forkPolicy = policyArg(args, "forkPolicy", DYNAMIC);
ForkJoinPool g = new ForkJoinPool(procs);
System.out.println("Integrating from " + start + " to " + end +
" forkPolicy = " + forkPolicy);
long lastTime = System.nanoTime();
for (int reps = intArg(args, "reps", 10); reps > 0; reps--) {
double a;
if (forkPolicy == SERIAL)
a = SQuad.computeArea(g, start, end);
else if (forkPolicy == FORK)
a = FQuad.computeArea(g, start, end);
else
a = DQuad.computeArea(g, start, end);
long now = System.nanoTime();
double s = (double) (now - lastTime) / NPS;
lastTime = now;
System.out.printf("Calls/sec: %12d", (long) (calls / s));
System.out.printf(" Time: %7.3f", s);
System.out.printf(" Area: %12.1f", a);
System.out.println();
}
System.out.println(g);
g.shutdown();
}
示例8: testSubmitAfterShutdown
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* A task submitted after shutdown is rejected
*/
public void testSubmitAfterShutdown() {
ForkJoinPool p = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(p)) {
p.shutdown();
assertTrue(p.isShutdown());
try {
ForkJoinTask<Integer> f = p.submit(new FibTask(8));
shouldThrow();
} catch (RejectedExecutionException success) {}
}
}
示例9: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Main method of the example
* @param args
*/
public static void main(String[] args) {
// Generate an array of 1000 integers
ArrayGenerator generator=new ArrayGenerator();
int array[]=generator.generateArray(1000);
// Create a TaskManager object
TaskManager manager=new TaskManager();
// Create a ForkJoinPool with the default constructor
ForkJoinPool pool=new ForkJoinPool();
// Create a Task to process the array
SearchNumberTask task=new SearchNumberTask(array,0,1000,5,manager);
// Execute the task
pool.execute(task);
// Shutdown the pool
pool.shutdown();
// Wait for the finalization of the task
try {
pool.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Write a message to indicate the end of the program
System.out.printf("Main: The program has finished\n");
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:37,代码来源:Main.java
示例10: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Main method of the example
* @param args
*/
public static void main(String[] args) {
// Create a list of products
ProductListGenerator generator=new ProductListGenerator();
List<Product> products=generator.generate(10000);
// Craete a task
Task task=new Task(products, 0, products.size(), 0.20);
// Create a ForkJoinPool
ForkJoinPool pool=new ForkJoinPool();
// Execute the Task
pool.execute(task);
// Write information about the pool
do {
System.out.printf("******************************************\n");
System.out.printf("Main: Parallelism: %d\n",pool.getParallelism());
System.out.printf("Main: Active Threads: %d\n",pool.getActiveThreadCount());
System.out.printf("Main: Task Count: %d\n",pool.getQueuedTaskCount());
System.out.printf("Main: Steal Count: %d\n",pool.getStealCount());
System.out.printf("******************************************\n");
try {
TimeUnit.MILLISECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (!task.isDone());
// Shutdown the pool
pool.shutdown();
// Check if the task has completed normally
if (task.isCompletedNormally()){
System.out.printf("Main: The process has completed normally.\n");
}
// Expected result: 12. Write products which price is not 12
for (int i=0; i<products.size(); i++){
Product product=products.get(i);
if (product.getPrice()!=12) {
System.out.printf("Product %s: %f\n",product.getName(),product.getPrice());
}
}
// End of the program
System.out.println("Main: End of the program.\n");
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:55,代码来源:Main.java
示例11: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/*
* Create the Fork/Join pool
*/
ForkJoinPool pool=new ForkJoinPool();
/*
* Create a new Array of integer numbers with 10000 elements
*/
int array[]=new int[10000];
/*
* Create a new task
*/
Task task1=new Task(array,0,array.length);
/*
* Execute the task in the Fork/Join pool
*/
pool.execute(task1);
/*
* Wait for the finalization of the task writing information
* about the pool every second
*/
while (!task1.isDone()) {
showLog(pool);
TimeUnit.SECONDS.sleep(1);
}
/*
* Shutdown the pool
*/
pool.shutdown();
/*
* Wait for the finalization of the pool
*/
pool.awaitTermination(1, TimeUnit.DAYS);
/*
* End of the program
*/
showLog(pool);
System.out.printf("Main: End of the program.\n");
}
示例12: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/*
* Create a new MyWorkerThreadFactory
*/
MyWorkerThreadFactory factory=new MyWorkerThreadFactory();
/*
* Create new ForkJoinPool, passing as parameter the factory created before
*/
ForkJoinPool pool=new ForkJoinPool(4, factory, null, false);
/*
* Create and initializes the elements of the array
*/
int array[]=new int[100000];
for (int i=0; i<array.length; i++){
array[i]=1;
}
/*
* Create a new Task to sum the elements of the array
*/
MyRecursiveTask task=new MyRecursiveTask(array,0,array.length);
/*
* Send the task to the ForkJoinPool
*/
pool.execute(task);
/*
* Wait for the finalization of the task
*/
task.join();
/*
* Shutdown the pool
*/
pool.shutdown();
/*
* Wait for the finalization of the pool
*/
pool.awaitTermination(1, TimeUnit.DAYS);
/*
* Write the result of the task
*/
System.out.printf("Main: Result: %d\n",task.get());
/*
* Write a message indicating the end of the program
*/
System.out.printf("Main: End of the program\n");
}
示例13: main
import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
* Main method of the example
*/
public static void main(String[] args) {
// Create the pool
ForkJoinPool pool=new ForkJoinPool();
// Create three FolderProcessor tasks for three diferent folders
FolderProcessor system=new FolderProcessor("C:\\Windows", "log");
FolderProcessor apps=new FolderProcessor("C:\\Program Files","log");
FolderProcessor documents=new FolderProcessor("C:\\Documents And Settings","log");
// Execute the three tasks in the pool
pool.execute(system);
pool.execute(apps);
pool.execute(documents);
// Write statistics of the pool until the three tasks end
do {
System.out.printf("******************************************\n");
System.out.printf("Main: Parallelism: %d\n",pool.getParallelism());
System.out.printf("Main: Active Threads: %d\n",pool.getActiveThreadCount());
System.out.printf("Main: Task Count: %d\n",pool.getQueuedTaskCount());
System.out.printf("Main: Steal Count: %d\n",pool.getStealCount());
System.out.printf("Main: %b - %b - %b\n",system.isDone(), apps.isDone(), documents.isDone());
System.out.printf("Main: %d - %d - %d\n",system.getPendingCount(), apps.getPendingCount(), documents.getPendingCount());
System.out.printf("******************************************\n");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while ((!system.isDone())||(!apps.isDone())||(!documents.isDone()));
// Shutdown the pool
pool.shutdown();
// Write the number of results calculate by each task
List<String> results;
results=system.getResultList();
System.out.printf("System: %d files found.\n",results.size());
results=apps.getResultList();
System.out.printf("Apps: %d files found.\n",results.size());
results=documents.getResultList();
System.out.printf("Documents: %d files found.\n",results.size());
}