Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 368581
Collapse All | Expand All

(-)a/bundles/org.eclipse.core.jobs/META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Manifest-Version: 1.0 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.core.jobs; singleton:=true
4
Bundle-SymbolicName: org.eclipse.core.jobs; singleton:=true
5
Bundle-Version: 3.5.100.qualifier
5
Bundle-Version: 3.5.101.qualifier
6
Bundle-Vendor: %providerName
6
Bundle-Vendor: %providerName
7
Bundle-Localization: plugin
7
Bundle-Localization: plugin
8
Export-Package: org.eclipse.core.internal.jobs;x-internal:=true,
8
Export-Package: org.eclipse.core.internal.jobs;x-internal:=true,
(-)a/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/WorkerPool.java (-1 / +1 lines)
Lines 240-246 class WorkerPool { Link Here
240
					manager.getLockManager().addLockThread(Thread.currentThread(), job.getRule());
240
					manager.getLockManager().addLockThread(Thread.currentThread(), job.getRule());
241
				}
241
				}
242
				//see if we need to wake another worker
242
				//see if we need to wake another worker
243
				if (manager.sleepHint() <= 0)
243
				if (manager.sleepHint() < InternalJob.T_INFINITE)
244
					jobQueued();
244
					jobQueued();
245
			}
245
			}
246
		} finally {
246
		} finally {
(-)a/tests/org.eclipse.core.tests.runtime/META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Manifest-Version: 1.0 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Eclipse Core Tests Runtime
3
Bundle-Name: Eclipse Core Tests Runtime
4
Bundle-SymbolicName: org.eclipse.core.tests.runtime; singleton:=true
4
Bundle-SymbolicName: org.eclipse.core.tests.runtime; singleton:=true
5
Bundle-Version: 3.7.1.qualifier
5
Bundle-Version: 3.7.2.qualifier
6
Bundle-ClassPath: runtimetests.jar
6
Bundle-ClassPath: runtimetests.jar
7
Bundle-Activator: org.eclipse.core.tests.runtime.RuntimeTestsPlugin
7
Bundle-Activator: org.eclipse.core.tests.runtime.RuntimeTestsPlugin
8
Bundle-Vendor: Eclipse.org
8
Bundle-Vendor: Eclipse.org
(-)a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/jobs/Bug_366170.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 * 	ivan.motsch@bsiag.com - initial example
10
 *     IBM Corporation - converted to JUnit test
11
 *******************************************************************************/
12
package org.eclipse.core.tests.runtime.jobs;
13
14
import java.util.concurrent.Semaphore;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.jobs.Job;
17
18
/**
19
 * Tests that scheduling multiple jobs with a delay and then blocking all active
20
 * worker threads doesn't cause job manager to starve. This is a regression
21
 * test for a situation where all worker threads were blocked and no workers
22
 * were available to process sleeping jobs awaiting execution. For details see:
23
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=366170
24
 */
25
public class Bug_366170 extends AbstractJobManagerTest {
26
	private Semaphore m_jobBStopHint = new Semaphore(1);
27
28
	public void testBug() throws Exception {
29
		System.out.println("--- Running the examle ---");
30
		m_jobBStopHint.acquire();
31
		scheduleJobA(200);
32
		scheduleJobC(300);
33
34
		Thread.sleep(2000L);
35
36
		//lock should now be free if C is finished
37
		assertTrue("Failed: Job C was not run", m_jobBStopHint.tryAcquire());
38
	}
39
40
	private void scheduleJobA(long delay) throws Exception {
41
		Job job = new Job("A") {
42
			@Override
43
			public boolean shouldSchedule() {
44
				System.out.println("schedule " + getName());
45
				return true;
46
			}
47
48
			protected IStatus run(IProgressMonitor monitor) {
49
				System.out.println("begin " + getName());
50
				try {
51
					scheduleJobB(0).join();
52
				} catch (Throwable t) {
53
					t.printStackTrace();
54
				}
55
				System.out.println("end   " + getName());
56
				return Status.OK_STATUS;
57
			}
58
		};
59
		job.setSystem(true);
60
		job.schedule(delay);
61
	}
62
63
	private Job scheduleJobB(long delay) throws Exception {
64
		Job job = new Job("B") {
65
			@Override
66
			public boolean shouldSchedule() {
67
				System.out.println("schedule " + getName());
68
				return true;
69
			}
70
71
			@Override
72
			protected IStatus run(IProgressMonitor monitor) {
73
				System.out.println("begin " + getName());
74
				try {
75
					m_jobBStopHint.acquire();
76
				} catch (InterruptedException e) {
77
					e.printStackTrace();
78
				}
79
				m_jobBStopHint.release();
80
				System.out.println("end   " + getName());
81
				return Status.OK_STATUS;
82
			}
83
		};
84
		job.setSystem(true);
85
		job.schedule(delay);
86
		return job;
87
	}
88
89
	private void scheduleJobC(long delay) throws Exception {
90
		Job job = new Job("C") {
91
			@Override
92
			public boolean shouldSchedule() {
93
				System.out.println("schedule " + getName());
94
				return true;
95
			}
96
97
			@Override
98
			protected IStatus run(IProgressMonitor monitor) {
99
				System.out.println("begin " + getName());
100
				m_jobBStopHint.release();
101
				System.out.println("end   " + getName());
102
				return Status.OK_STATUS;
103
			}
104
		};
105
		job.setSystem(true);
106
		job.schedule(delay);
107
	}
108
109
}

Return to bug 368581