summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Ptaszkiewicz2012-06-22 16:13:27 (EDT)
committer John Arthorne2012-06-22 16:13:27 (EDT)
commitda78c4106579f856e35e6969cd5d454d54696452 (patch)
tree767119d44c474e85eea59c25342ba566254e66c5
parent2d6e94e8ac1415af460dcfcac5901a5e9edfe146 (diff)
downloadeclipse.platform.runtime-da78c4106579f856e35e6969cd5d454d54696452.zip
eclipse.platform.runtime-da78c4106579f856e35e6969cd5d454d54696452.tar.gz
eclipse.platform.runtime-da78c4106579f856e35e6969cd5d454d54696452.tar.bz2
Bug 283849 - [jobs] Job thread set too late
-rw-r--r--bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java3
-rw-r--r--bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/Worker.java1
-rw-r--r--bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java4
-rw-r--r--tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/JobTest.java14
4 files changed, 18 insertions, 4 deletions
diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java
index 04a6a9f..04c5cb8 100644
--- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java
+++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java
@@ -1472,7 +1472,7 @@ public class JobManager implements IJobManager {
* Returns the next job to be run, or null if no jobs are waiting to run.
* The worker must call endJob when the job is finished running.
*/
- protected Job startJob() {
+ protected Job startJob(Worker worker) {
Job job = null;
while (true) {
job = nextJob();
@@ -1492,6 +1492,7 @@ public class JobManager implements IJobManager {
if (shouldRun && !internal.isAboutToRunCanceled()) {
internal.setProgressMonitor(createMonitor(job));
//change from ABOUT_TO_RUN to RUNNING
+ internal.setThread(worker);
internal.internalSetState(Job.RUNNING);
internal.jobStateLock.notifyAll();
break;
diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/Worker.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/Worker.java
index 51d9eed..9fd2ef9 100644
--- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/Worker.java
+++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/Worker.java
@@ -48,7 +48,6 @@ public class Worker extends Thread {
setPriority(Thread.NORM_PRIORITY);
try {
while ((currentJob = pool.startJob(this)) != null) {
- currentJob.setThread(this);
IStatus result = Status.OK_STATUS;
try {
result = currentJob.run(currentJob.getProgressMonitor());
diff --git a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java
index 635440e..f876633 100644
--- a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java
+++ b/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java
@@ -211,14 +211,14 @@ class WorkerPool {
}
Job job = null;
try {
- job = manager.startJob();
+ job = manager.startJob(worker);
//spin until a job is found or until we have been idle for too long
long idleStart = System.currentTimeMillis();
while (manager.isActive() && job == null) {
long hint = manager.sleepHint();
if (hint > 0)
sleep(Math.min(hint, BEST_BEFORE));
- job = manager.startJob();
+ job = manager.startJob(worker);
//if we were already idle, and there are still no new jobs, then
// the thread can expire
synchronized (this) {
diff --git a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/JobTest.java b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/JobTest.java
index 0248a08..4ead549 100644
--- a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/JobTest.java
+++ b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/JobTest.java
@@ -1352,6 +1352,20 @@ public class JobTest extends AbstractJobTest {
//execution thread should reset to null after job is finished
assertTrue("9.0", longJob.getThread() == null);
+
+ //when the state is changed to RUNNING, the thread should not be null
+ final Thread[] thread = new Thread[1];
+ IJobChangeListener listener = new JobChangeAdapter() {
+ public void running(IJobChangeEvent event) {
+ thread[0] = event.getJob().getThread();
+ }
+ };
+ longJob.addJobChangeListener(listener);
+ longJob.schedule();
+ waitForState(longJob, Job.RUNNING);
+ longJob.cancel();
+ longJob.removeJobChangeListener(listener);
+ assertNotNull("10.0", thread[0]);
}
/**