Created
April 28, 2012 13:11
-
-
Save peterneubauer/2518979 to your computer and use it in GitHub Desktop.
Multithread test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed to Neo Technology under one or more contributor | |
* license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright | |
* ownership. Neo Technology licenses this file to you under | |
* the Apache License, Version 2.0 (the "License"); you may | |
* not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
package org.neo4j.examples; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import org.junit.Test; | |
import org.neo4j.graphdb.Node; | |
import org.neo4j.graphdb.Relationship; | |
import org.neo4j.test.GraphDescription.Graph; | |
public class ThreadTest extends AbstractJavaDocTestbase | |
{ | |
@Graph( { "a knows b" } ) | |
@Test | |
public void threads() | |
{ | |
data.get(); | |
ExecutorService exec = Executors.newFixedThreadPool( 2 ); | |
try | |
{ | |
for ( int i = 0; i < 2; i++ ) | |
{ | |
exec.submit( new Runnable() | |
{ | |
@Override | |
public void run() | |
{ | |
for ( Node start : graphdb().getAllNodes() ) | |
{ | |
System.out.println( start ); | |
for ( Relationship r : start.getRelationships() ) | |
{ | |
System.out.println( r ); | |
} | |
} | |
} | |
} ); | |
} | |
} | |
finally | |
{ | |
exec.shutdown(); | |
} | |
} | |
} | |
Output: | |
Node[1] | |
Relationship[0] | |
Node[2] | |
Relationship[0] | |
Node[1] | |
Relationship[0] | |
Node[2] | |
Relationship[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment