* handleException().
*/
@Test
public void testMultithreadAccess() throws IOException, InterruptedException
{
RecordManager recman;
BTree<String, Integer> tree;
recman = RecordManagerFactory.createRecordManager( getTemporaryFile( "testMultithreadAccess" ) );
tree = new BTree<String, Integer>( recman, new StringComparator() );
TestThread<String, Integer>[] threadPool = ( TestThread<String, Integer>[] ) new TestThread[THREAD_NUMBER];
String name;
Map<String, Integer> content;
// create content for the tree, different content for different threads!
for ( int threadCount = 0; threadCount < THREAD_NUMBER; threadCount++ )
{
name = "thread" + threadCount;
content = new TreeMap<String, Integer>();
for ( int contentCount = 0; contentCount < THREAD_CONTENT_SIZE; contentCount++ )
{
// guarantee, that keys and values do not overleap,
// otherwise one thread removes some keys/values of
// other threads!
content.put( name + "_" + contentCount,
Integer.valueOf( threadCount * THREAD_CONTENT_SIZE + contentCount ) );
}
threadPool[threadCount] = new TestThread<String, Integer>( name, tree, content );
threadPool[threadCount].start();
}
Thread.sleep( THREAD_RUNTIME );
// stop threads:
for ( int threadCount = 0; threadCount < THREAD_NUMBER; threadCount++ )
{
threadPool[threadCount].setStop();
}
// wait until the threads really stop:
try
{
for ( int threadCount = 0; threadCount < THREAD_NUMBER; threadCount++ )
{
threadPool[threadCount].join();
}
}
catch ( InterruptedException ignore )
{
ignore.printStackTrace();
}
recman.close();
}