01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.synth.thread;
07:
08: import java.sql.Connection;
09: import java.sql.DriverManager;
10: import java.sql.SQLException;
11:
12: import org.h2.test.TestBase;
13:
14: /**
15: * Starts multiple threads and performs random operations on each thread.
16: */
17: public class TestMulti extends TestBase {
18:
19: public volatile boolean stop;
20:
21: public void test() throws Exception {
22: Class.forName("org.h2.Driver");
23: deleteDb(baseDir, "openClose");
24:
25: // int len = getSize(5, 100);
26: int len = 10;
27: TestMultiThread[] threads = new TestMultiThread[len];
28: for (int i = 0; i < len; i++) {
29: threads[i] = new TestMultiNews(this );
30: }
31: threads[0].first();
32: for (int i = 0; i < len; i++) {
33: threads[i].start();
34: }
35: Thread.sleep(10000);
36: this .stop = true;
37: for (int i = 0; i < len; i++) {
38: threads[i].join();
39: }
40: threads[0].finalTest();
41: }
42:
43: public Connection getConnection() throws SQLException {
44: final String url = "jdbc:h2:" + baseDir
45: + "/openClose;LOCK_MODE=3;DB_CLOSE_DELAY=-1";
46: Connection conn = DriverManager.getConnection(url, "sa", "");
47: return conn;
48: }
49:
50: }
|