本文整理汇总了Java中java.util.concurrent.ExecutorService.isTerminated方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutorService.isTerminated方法的具体用法?Java ExecutorService.isTerminated怎么用?Java ExecutorService.isTerminated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ExecutorService
的用法示例。
在下文中一共展示了ExecutorService.isTerminated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownAndCancelTask
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
private static void shutdownAndCancelTask(ExecutorService execService, int shutdownDelaySec, String name, Future future) {
try {
execService.shutdown();
System.out.println("Waiting for " + shutdownDelaySec + " sec before shutting down service...");
execService.awaitTermination(shutdownDelaySec, TimeUnit.SECONDS);
} catch (Exception ex) {
System.out.println("Caught around execService.awaitTermination(): " + ex.getClass().getName());
} finally {
if (!execService.isTerminated()) {
System.out.println("Terminating remaining running tasks...");
if (future != null && !future.isDone() && !future.isCancelled()) {
System.out.println("Cancelling task " + name + "...");
future.cancel(true);
}
}
System.out.println("Calling execService.shutdownNow()...");
List<Runnable> l = execService.shutdownNow();
System.out.println(l.size() + " tasks were waiting to be executed. Service stopped.");
}
}
示例2: stop
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
static void stop(ExecutorService executor) {
try {
System.out.println("attempt to shutdown executor");
executor.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
System.err.println("termination interrupted");
}
finally {
if (!executor.isTerminated()) {
System.err.println("killing non-finished tasks");
}
executor.shutdownNow();
System.out.println("shutdown finished");
}
}
示例3: clearData
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
private void clearData(Map<File,DataNode> map,TableMigrateInfo table){
if(table.isError()) {
return;
}
ExecutorService executor = new ThreadPoolExecutor(margs.getThreadCount(), margs.getThreadCount(),
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
Iterator<Entry<File,DataNode>> it = map.entrySet().iterator();
while(it.hasNext()){
Entry<File,DataNode> et = it.next();
File f =et.getKey();
DataNode srcDn = et.getValue();
executor.execute(new DataClearRunner(table, srcDn, f));
}
executor.shutdown();
while(true){
if(executor.isTerminated()){
break;
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
LOGGER.error("error",e);
}
}
}
示例4: awaitExecutorTermination
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
/**
* Wait for specified executor to complete
* @param executor
* @param timeoutMillis Number of milliseconds to wait until forcibly shutting down
*/
public static void awaitExecutorTermination(ExecutorService executor, long timeoutMillis) {
try {
// wait for all executors to complete
executor.awaitTermination(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// nothing to do, shutting down
} finally {
// shutdown all running processes
if (!executor.isTerminated()) {
logger.warn("Forcing shutdown for {}", executor);
executor.shutdownNow();
}
}
}
示例5: insert
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
private void insert(String insertType) throws InterruptedException {
this.logger.write("Start to insert" + insertType + ".");
Iterator<Inserter> iter = this.factory.inserters(insertType);
ExecutorService pool = Executors.newFixedThreadPool(this.threads);
while (iter.hasNext())
pool.execute(iter.next());
pool.shutdown();
while (true) {
if (pool.isTerminated()) {
this.logger.write("Finish " + insertType + " insert.");
break;
}
Thread.sleep(20);
}
}
示例6: testWrite_MultipleWriters
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
/**
* Test for multiple writers running in separate threads, writing data simultaneously.
*
* @throws RMIException
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testWrite_MultipleWriters() throws RMIException, IOException, InterruptedException {
// System.out.println("MonarchRecordWriterTest.testWrite_MultipleWriters");
final List<String> lines = TestHelper.getResourceAsString(resourceFile);
final Map<String, Integer> expectedMap = new HashMap<String, Integer>(4) {{
put("0", 10);
put("1", 10);
put("2", 10);
put("3", 1);
}};
final int blockSize = 10;
ExecutorService es = Executors.newFixedThreadPool(3);
for (int i = 0; i < 3; i++) {
final String tid = "000_" + i;
es.submit(() -> {
try {
assertOnRecordWriter(lines, expectedMap, tid, blockSize);
} catch (Exception e) {
fail("No exception expected: " + e.getMessage());
}
});
}
es.shutdown();
es.awaitTermination(5, TimeUnit.SECONDS);
if (!es.isTerminated()) {
es.shutdownNow();
}
Configuration conf = new Configuration();
conf.set("monarch.locator.port", testBase.getLocatorPort());
}
示例7: stop
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public static void stop(ExecutorService executor) {
try {
executor.shutdown();
executor.awaitTermination(60, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
System.err.println("termination interrupted");
}
finally {
if (!executor.isTerminated()) {
System.err.println("killing non-finished tasks");
}
executor.shutdownNow();
}
}
示例8: main
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public static void main(String[] args)
{
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i < 10; i++)
{
Runnable worker = new WorkerThread("" + i);
executor.execute(worker);
}
executor.shutdown();
while (!executor.isTerminated())
{
}
System.out.println("Finished all threads");
}
示例9: shutdownExecutor
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public static void shutdownExecutor(ExecutorService executor) {
executor.shutdown();
try {
executor.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (! executor.isTerminated()) {
Logger.logShutdownMessage("some threads didn't terminate, forcing shutdown");
executor.shutdownNow();
}
}
示例10: executeSameTimeJob
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
/**
* 并行任务处理方式
*/
private boolean executeSameTimeJob(final long groupId, final Queue<JobVo> jobQueue) {
final List<Boolean> result = new ArrayList<Boolean>(0);
final Semaphore semaphore = new Semaphore(jobQueue.size());
ExecutorService exec = Executors.newCachedThreadPool();
for (final JobVo jobVo : jobQueue) {
Runnable task = new Runnable() {
@Override
public void run() {
try {
semaphore.acquire();
result.add(doFlowJob(jobVo, groupId));
semaphore.release();
} catch (Exception e) {
e.printStackTrace();
}
}
};
exec.submit(task);
}
exec.shutdown();
while (true) {
if (exec.isTerminated()) {
logger.info("[opencron]SameTimeJob,All doned!");
return !result.contains(false);
}
}
}
示例11: scanportsetfun
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public void scanportsetfun() {
int threadNum;
threadNum=Integer.parseInt(TheardNum.getText().trim());
String[] portsString = textportlist.getText().split(",");
int[] ports = new int[portsString.length];
for(int ii=0;ii<portsString.length;ii++)
ports[ii] = Integer.parseInt(portsString[ii].trim());
Result.append("scanning"+" "+Lsaportscan.hostaddress+"'s port set!"+"\n");
ExecutorService threadPool = Executors.newCachedThreadPool();
for (int i = 0; i < threadNum; i++) {
Portset portset = new Portset(ports,threadNum,i);
threadPool.execute(portset);
}
threadPool.shutdown();
while (true) {
if (threadPool.isTerminated()) {
//System.out.println("OVER!!!!!!!!!!!!!!!");
Result.append("-------------------------Over!!!----------------------\n\n");
stateResult.setText("OVER !");
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
}
}
示例12: multiThreadedPersist
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
@Test
public void multiThreadedPersist() throws RepositoryException, InterruptedException {
final PersistenceService persistenceService = new PersistenceService(host, port, adminUser, adminPassword);
//persist data with multiple threads against the persistence service - simulate multiple concurrent requests against a tomcat deployed ingestion service
//results in intermittent MarkLogicTransactionExceptions in executor threads
ExecutorService executorService = Executors.newFixedThreadPool(10);
try {
for(final String identifier: identifiers) {
for (int i=0; i<20; i++) {
executorService.submit(
new Runnable() {
@Override
public void run() {
persistenceService.persist(entitiesFor(identifier));
}
}
);
}
}
executorService.shutdown();
executorService.awaitTermination(60, TimeUnit.SECONDS);
} finally {
if(!executorService.isTerminated()) {
System.out.println("cancel non finished tasks");
}
executorService.shutdownNow();
System.out.println("shut down finished");
}
}
示例13: test_multi
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
@Test
public void test_multi() {
// 使用ConcurrentHashMap代替HashSet(内部使用HashMap,不适用于并发),以应用于并发条件下
final ConcurrentMap<Singleton2 ,Boolean> map = new ConcurrentHashMap<>() ;
ExecutorService exec = Executors.newFixedThreadPool(200) ;
// 约定一个执行时间(模拟并发,原因是类比较简单,初始化速度太快,无法真实再现并发情况)
final long moment = System.currentTimeMillis() + 1000 ;
for (int i = 0; i < 1000; i++) {
exec.execute(new Runnable() {
@Override
public void run() {
while (true) {
// 到约定时间后再执行(构成并发)
if (moment < System.currentTimeMillis()) {
map.put(Singleton2.getInstance() ,Boolean.TRUE) ;
break;
}
}
}
});
}
exec.shutdown();
while (!exec.isTerminated()) ;
// 如果元素个数为1,表示未生成不同实例
Assert.assertTrue(map.size() > 1);
}
示例14: test_multi
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
@Test
public void test_multi() {
// 使用ConcurrentHashMap代替HashSet(内部使用HashMap,不适用于并发),以应用于并发条件下
final ConcurrentMap<Singleton6 ,Boolean> map = new ConcurrentHashMap<>() ;
ExecutorService exec = Executors.newFixedThreadPool(400) ;
// 约定一个执行时间(模拟并发,原因是类比较简单,初始化速度太快,无法真实再现并发情况)
final long moment = System.currentTimeMillis() + 1000 ;
for (int i = 0; i < 1000; i++) {
exec.execute(new Runnable() {
@Override
public void run() {
while (true) {
// 到约定时间后再执行(构成并发)
if (moment < System.currentTimeMillis()) {
map.put(Singleton6.INSTANCE ,Boolean.TRUE) ;
break;
}
}
}
});
}
exec.shutdown();
while (!exec.isTerminated()) ;
// 如果元素个数为1,表示未生成不同实例
Assert.assertEquals(1 ,map.size());
}
示例15: test_multi
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
@Test
public void test_multi() {
// 使用ConcurrentHashMap代替HashSet(内部使用HashMap,不适用于并发),以应用于并发条件下
final ConcurrentMap<Singleton4 ,Boolean> map = new ConcurrentHashMap<>() ;
ExecutorService exec = Executors.newFixedThreadPool(400) ;
// 约定一个执行时间(模拟并发,原因是类比较简单,初始化速度太快,无法真实再现并发情况)
final long moment = System.currentTimeMillis() + 1000 ;
for (int i = 0; i < 1000; i++) {
exec.execute(new Runnable() {
@Override
public void run() {
while (true) {
// 到约定时间后再执行(构成并发)
if (moment < System.currentTimeMillis()) {
map.put(Singleton4.getInstance() ,Boolean.TRUE) ;
break;
}
}
}
});
}
exec.shutdown();
while (!exec.isTerminated()) ;
// 如果元素个数为1,表示未生成不同实例
Assert.assertEquals(1 ,map.size());
}