org.scijava.thread.ThreadService Java Examples

The following examples show how to use org.scijava.thread.ThreadService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SciView.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Static launching method
 */
public static SciView create() throws Exception {
    SceneryBase.xinitThreads();

    System.setProperty( "scijava.log.level:sc.iview", "debug" );
    Context context = new Context( ImageJService.class, SciJavaService.class, SCIFIOService.class, ThreadService.class);

    SciViewService sciViewService = context.service( SciViewService.class );
    SciView sciView = sciViewService.getOrCreateActiveSciView();

    return sciView;
}
 
Example #2
Source File: REPLEditor.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ThreadService threadService() {
  // HACK: Get the SciJava context from the REPL.
  // This can be fixed if/when the REPL offers a getter for it.
  final Context ctx = (Context) ClassUtils.getValue(//
          Types.field(repl.getClass(), "context"), repl);
  return ctx.service(ThreadService.class);
}
 
Example #3
Source File: SciViewTest.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void nestedNodeDeletionTest() throws Exception {
    SceneryBase.xinitThreads();

    System.setProperty( "scijava.log.level:sc.iview", "debug" );
    Context context = new Context( ImageJService.class, SciJavaService.class, SCIFIOService.class, ThreadService.class);

    SciViewService sciViewService = context.service( SciViewService.class );
    SciView sciView = sciViewService.getOrCreateActiveSciView();

    Group group = new Group();

    final Material material = new Material();
    material.setAmbient( new Vector3f( 1.0f, 0.0f, 0.0f ) );
    material.setDiffuse( new Vector3f( 1.0f, 0.0f, 0.0f ) );
    material.setSpecular( new Vector3f( 1.0f, 1.0f, 1.0f ) );

    final Sphere sphere = new Sphere( 1, 20 );
    sphere.setMaterial( material );
    sphere.setPosition( JOMLVector3.convert( new JOMLVector3(0,0,0) ) );
    //sphere.setParent(group);
    group.addChild(sphere);
    sciView.addNode(group);

    Assert.assertEquals( sciView.getAllSceneNodes().length, 7 );

    sciView.deleteNode(group);

    Assert.assertEquals( sciView.getAllSceneNodes().length, 6 );

    sciView.closeWindow();
}
 
Example #4
Source File: FormatServiceTest.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Test simultaneous format caching on multiple threads.
 * <p>
 * NB: not annotated as a unit test due to length of execution.
 * </p>
 */
@Ignore
@Test
public void testMultiThreaded() throws InterruptedException {
	final ThreadService ts = formatService.getContext().service(
		ThreadService.class);
	final Random random = new Random();
	final long baseTime = System.currentTimeMillis();

	final int threads = 500;
	final int[] count = new int[1];

	final Runnable runnable = () -> {
		final long time = System.currentTimeMillis();

		while (System.currentTimeMillis() - time < 10000) {
			final String s = new BigInteger(64, random).toString() + ".tif";
			try {
				formatService.getFormat(new FileLocation(s));
			}
			catch (final FormatException exc) {
				return;
			}
		}

		synchronized (count) {
			count[0]++;
		}
	};

	for (int i = 0; i < threads; i++) {
		ts.run(runnable);
	}

	while (System.currentTimeMillis() - baseTime < 30000) {
		Thread.sleep(100);
	}

	assertEquals(threads, count[0]);
}
 
Example #5
Source File: SciViewTest.java    From sciview with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void nodeDeletionTest() throws Exception {
    SceneryBase.xinitThreads();

    System.setProperty( "scijava.log.level:sc.iview", "debug" );
    Context context = new Context( ImageJService.class, SciJavaService.class, SCIFIOService.class, ThreadService.class);

    SciViewService sciViewService = context.service( SciViewService.class );
    SciView sciView = sciViewService.getOrCreateActiveSciView();

    Node sphere = sciView.addSphere();

    Assert.assertEquals( sciView.getAllSceneNodes().length, 7 );

    sciView.deleteNode(sphere);

    Assert.assertEquals( sciView.getAllSceneNodes().length, 6 );

    sciView.closeWindow();
}