本文整理了Java中java.util.concurrent.ThreadPoolExecutor.runWorker()
方法的一些代码示例,展示了ThreadPoolExecutor.runWorker()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.runWorker()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:runWorker
[英]Main worker run loop. Repeatedly gets tasks from queue and executes them, while coping with a number of issues: 1. We may start out with an initial task, in which case we don't need to get the first one. Otherwise, as long as pool is running, we get tasks from getTask. If it returns null then the worker exits due to changed pool state or configuration parameters. Other exits result from exception throws in external code, in which case completedAbruptly holds, which usually leads processWorkerExit to replace this thread. 2. Before running any task, the lock is acquired to prevent other pool interrupts while the task is executing, and then we ensure that unless pool is stopping, this thread does not have its interrupt set. 3. Each task run is preceded by a call to beforeExecute, which might throw an exception, in which case we cause thread to die (breaking loop with completedAbruptly true) without processing the task. 4. Assuming beforeExecute completes normally, we run the task, gathering any of its thrown exceptions to send to afterExecute. We separately handle RuntimeException, Error (both of which the specs guarantee that we trap) and arbitrary Throwables. Because we cannot rethrow Throwables within Runnable.run, we wrap them within Errors on the way out (to the thread's UncaughtExceptionHandler). Any thrown exception also conservatively causes thread to die. 5. After task.run completes, we call afterExecute, which may also throw an exception, which will also cause thread to die. According to JLS Sec 14.20, this exception is the one that will be in effect even if task.run throws. The net effect of the exception mechanics is that afterExecute and the thread's UncaughtExceptionHandler have as accurate information as we can provide about any problems encountered by user code.
[中]主要工人运行循环。重复地从队列中获取任务并执行它们,同时处理许多问题:1。我们可以从一个初始任务开始,在这种情况下,我们不需要得到第一个任务。否则,只要池在运行,我们就可以从getTask获取任务。如果返回null,则工作进程将由于池状态或配置参数的更改而退出。其他退出源于外部代码中的异常抛出,在这种情况下completedjustly保持不变,这通常会导致processWorkerExit替换该线程。2.在运行任何任务之前,获取锁以防止任务执行时其他池中断,然后我们确保除非池停止,否则该线程没有中断设置。3.每个任务运行之前都会调用beforeExecute,这可能会引发异常,在这种情况下,我们会导致线程在不处理任务的情况下死亡(使用CompletedTruntly true中断循环)。4.假设beforeExecute正常完成,我们运行任务,收集其抛出的任何异常以发送给afterExecute。我们分别处理RuntimeException、Error(这两个规范都保证我们可以捕获)和任意丢弃。因为我们无法在Runnable内重新播放丢弃的内容。运行时,我们将它们包装在退出时的错误中(到线程的UncaughtExceptionHandler)。任何抛出的异常也会保守地导致线程死亡。5.任务完成后。运行完成后,我们调用afterExecute,它也可能引发异常,这也会导致线程死亡。根据JLS第14.20节,此例外情况将生效,即使任务已完成。快跑投球。异常机制的最终效果是,afterExecute和线程的UncaughtExceptionHandler具有尽可能准确的信息,我们可以提供有关用户代码遇到的任何问题的信息。
代码示例来源:origin: robovm/robovm
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: stackoverflow.com
java ExecuteSubmitDemo
creating service
a and b=4:0
Exception in thread "pool-1-thread-1" java.lang.ArithmeticException: / by zero
at ExecuteSubmitDemo$1.run(ExecuteSubmitDemo.java:14)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
代码示例来源:origin: stackoverflow.com
"pool-9-thread-1" #49 prio=5 os_prio=0 tid=0x00007ffd508e8000 nid=0x3a0c runnable [0x00007ffd188b6000]
java.lang.Thread.State: RUNNABLE
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
代码示例来源:origin: ibinti/bugvm
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: MobiVM/robovm
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: com.gluonhq/robovm-rt
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: FlexoVM/flexovm
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: com.bugvm/bugvm-rt
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: jtulach/bck2brwsr
/** Delegates main run loop to outer runWorker */
public void run() {
runWorker(this);
}
代码示例来源:origin: stackoverflow.com
06-30 14:11:48.803 3023-29855/? E/ClientConnectionOperation﹕ Handling authorization failure
com.google.android.gms.drive.auth.c: Authorization failed: Unsupported scope: https://www.googleapis.com/auth/drive
at com.google.android.gms.drive.auth.g.a(SourceFile:77)
at com.google.android.gms.drive.api.g.<init>(SourceFile:226)
at com.google.android.gms.drive.api.a.k.a(SourceFile:46)
at com.google.android.gms.common.service.g.run(SourceFile:178)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)`
代码示例来源:origin: stackoverflow.com
"pool-9-thread-32" #304 prio=5 os_prio=0 tid=0x000000002a706800 nid=0x348c waiting for monitor entry [0x000000003f06e000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.example.MyClass.method1(MyClass.java:400)
- waiting to lock <0x0000000680837b90> (a com.example.DifferentClass)
at com.example.MyClass.query(MyClass.java:500)
... omitted ...
at java.util.concurrent.FutureTask.run(FutureTask.java:270)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:618)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- <0x000000075bc59aa8> (a java.util.concurrent.ThreadPoolExecutor$Worker)
代码示例来源:origin: stackoverflow.com
java.io.IOException: Error returned: 10 Could not locate resource
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
代码示例来源:origin: stackoverflow.com
com.sun.deploy.net.FailedDownloadException: Unable to load resource: (http://host:port/webapp_name/app/jar-name.jar?version-id=1.5.0-20160707.182810-19, 1.5.0-20160707.182810-19)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.downloadResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
代码示例来源:origin: stackoverflow.com
07-07 18:06:31.469 7218-7260/cc.lait.d2.smack_demo E/Roster﹕ Exception reloading roster
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=s3Dmr-7)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (bare): e02b65a7bdc0f12662ac0d617e7eb3d1@iz23qr9ipxwz, FromMatchesFilter (full): iz23qr9ipxwz)).
at org.jivesoftware.smack.AbstractXMPPConnection$6.run(AbstractXMPPConnection.java:1438)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
代码示例来源:origin: stackoverflow.com
java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at so.TestCancel.main(TestCancel.java:69)
cancelled.
cancellation caused java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at so.TestCancel$1.call(TestCancel.java:64)
at so.TestCancel$1.call(TestCancel.java:61)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at so.TracingFutureTask.run(TestCancel.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
代码示例来源:origin: stackoverflow.com
java.util.ConcurrentModificationException
at java.util.HashMap$KeySet.forEach(HashMap.java:935)
at Cache.lambda$new$1(Cache.java:32)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
代码示例来源:origin: stackoverflow.com
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.IllegalStateException: Already connected
at java.net.URLConnection.checkNotConnected(URLConnection.java:464)
at java.net.URLConnection.setDoOutput(URLConnection.java:878)
内容来源于网络,如有侵权,请联系作者删除!