| /******************************************************************************* |
| * Copyright (c) 2006 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| ******************************************************************************/ |
| |
| package org.eclipse.ui.tests.concurrency; |
| |
| import junit.framework.*; |
| import org.eclipse.core.runtime.*; |
| import org.eclipse.core.runtime.jobs.ISchedulingRule; |
| import org.eclipse.ui.progress.UIJob; |
| |
| /** |
| * @since 3.2 |
| * |
| */ |
| public class TestBug138695 extends TestCase { |
| class SampleJob extends UIJob { |
| |
| /** |
| * @param name |
| */ |
| public SampleJob() { |
| super("Sample"); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) |
| */ |
| public IStatus runInUIThread(IProgressMonitor monitor) { |
| try { |
| Thread.sleep(100); |
| } catch (InterruptedException e) { |
| // TODO Auto-generated catch block |
| e.printStackTrace(); |
| } |
| return Status.OK_STATUS; |
| } |
| |
| } |
| |
| class SerialPerObjectRule implements ISchedulingRule { |
| |
| private Object fObject = null; |
| |
| public SerialPerObjectRule(Object lock) { |
| fObject = lock; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule) |
| */ |
| public boolean contains(ISchedulingRule rule) { |
| return rule == this; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule) |
| */ |
| public boolean isConflicting(ISchedulingRule rule) { |
| if (rule instanceof SerialPerObjectRule) { |
| SerialPerObjectRule vup = (SerialPerObjectRule) rule; |
| return fObject == vup.fObject; |
| } |
| return false; |
| } |
| |
| } |
| |
| public static Test suite() { |
| return new TestSuite(TestBug138695.class); |
| } |
| |
| public void testManyThreads() { |
| for (int i = 0; i < 1000; i++) { |
| SampleJob job = new SampleJob(); |
| job.setRule(new SerialPerObjectRule(this)); |
| job.schedule(); |
| } |
| |
| } |
| |
| } |