Initial commit from SVN.
This commit is contained in:
6
ThreadTest/.classpath
Normal file
6
ThreadTest/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
ThreadTest/.project
Normal file
17
ThreadTest/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ThreadTest</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
52
ThreadTest/src/com/threadtest/TestMain.java
Normal file
52
ThreadTest/src/com/threadtest/TestMain.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.threadtest;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2009<p>
|
||||
*/
|
||||
public class TestMain {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// System.out.println("Starting test");
|
||||
// new Thread(new Runnable() {
|
||||
// public void run() {
|
||||
// System.out.println("Inside thread.");
|
||||
// }
|
||||
// }).start();
|
||||
//
|
||||
// System.out.println("Thread started");
|
||||
// try {
|
||||
// synchronized(TestMain.class) {
|
||||
// TestMain.class.wait(0);
|
||||
// }
|
||||
// }
|
||||
// catch(Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
//TestObject.getSingleton();
|
||||
|
||||
// System.out.println("Starting SWT event loop thread.");
|
||||
// Thread t = new Thread(TestObject.getSingleton());
|
||||
//
|
||||
// t.start();
|
||||
//
|
||||
// System.out.println("Synchronzing");
|
||||
// synchronized(TestObject.getSingleton()) {
|
||||
// while(!TestObject.getSingleton().isInitialized) {
|
||||
// System.out.println("Waiting for isInitialized");
|
||||
// try {
|
||||
// TestObject.getSingleton().wait(0);
|
||||
// }//try//
|
||||
// catch(Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// }//catch//
|
||||
// }//while//
|
||||
// }//synchronized//
|
||||
|
||||
TestStarter.getSingleton();
|
||||
}
|
||||
|
||||
}
|
||||
88
ThreadTest/src/com/threadtest/TestObject.java
Normal file
88
ThreadTest/src/com/threadtest/TestObject.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.threadtest;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2009<p>
|
||||
*/
|
||||
public class TestObject implements Runnable {
|
||||
public static final TestObject singleton = new TestObject();
|
||||
|
||||
/** Whether the event thread has initialized. */
|
||||
public boolean isInitialized = false;
|
||||
|
||||
static {
|
||||
//System.out.println("Creating event loop");
|
||||
//singleton = new TestObject();
|
||||
//singleton.start();
|
||||
}
|
||||
/**
|
||||
* TestObject constructor.
|
||||
*/
|
||||
protected TestObject() {
|
||||
super();
|
||||
// System.out.println("Starting SWT event loop thread.");
|
||||
// Thread t = new Thread(this);
|
||||
//
|
||||
// t.start();
|
||||
//
|
||||
// System.out.println("Synchronzing");
|
||||
// synchronized(this) {
|
||||
// while(!isInitialized) {
|
||||
// System.out.println("Waiting for isInitialized");
|
||||
// try {
|
||||
// wait(0);
|
||||
// }//try//
|
||||
// catch(Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// }//catch//
|
||||
// }//while//
|
||||
// }//synchronized//
|
||||
}//TestObject()//
|
||||
public static TestObject getSingleton() {
|
||||
return singleton;
|
||||
}
|
||||
public void start() {
|
||||
System.out.println("Starting SWT event loop thread.");
|
||||
new Thread(this).start();
|
||||
|
||||
System.out.println("Synchronzing");
|
||||
synchronized(this) {
|
||||
while(!isInitialized) {
|
||||
System.out.println("Waiting for isInitialized");
|
||||
try {
|
||||
wait(0);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
}
|
||||
public void run() {
|
||||
System.out.println("SWT Event loop thread started.");
|
||||
// ThreadService.setIsInSingleThreadedContext(this);
|
||||
System.out.println("Creating display");
|
||||
// this.display = new Display();
|
||||
|
||||
System.out.println("Synchronizing to set isInitializing");
|
||||
synchronized(this) {
|
||||
System.out.println("Setting isInitializing");
|
||||
isInitialized = true;
|
||||
System.out.println("notifying");
|
||||
notifyAll();
|
||||
}//synchronized//
|
||||
|
||||
System.out.println("Entering loop");
|
||||
// enterEventLoop();
|
||||
|
||||
// Debug.log("Synchronzing to stop");
|
||||
// //Notify other threads that we have successfully stopped.//
|
||||
// synchronized(this) {
|
||||
// isStopped = true;
|
||||
// notifyAll();
|
||||
// }//synchronized//
|
||||
//
|
||||
// ThreadService.setIsInSingleThreadedContext(null);
|
||||
// //Dispose of the display so that this thread can once again be an event handler (for a different view).//
|
||||
// display.dispose();
|
||||
}//run()//
|
||||
}//TestObject//
|
||||
37
ThreadTest/src/com/threadtest/TestStarter.java
Normal file
37
ThreadTest/src/com/threadtest/TestStarter.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.threadtest;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2009<p>
|
||||
*/
|
||||
public class TestStarter {
|
||||
private static TestStarter singleton = new TestStarter();
|
||||
/**
|
||||
* TestStarter constructor.
|
||||
*/
|
||||
private TestStarter() {
|
||||
start();
|
||||
}
|
||||
public static TestStarter getSingleton() {
|
||||
return singleton;
|
||||
}
|
||||
private void start() {
|
||||
|
||||
System.out.println("Starting SWT event loop thread.");
|
||||
Thread t = new Thread(TestObject.getSingleton());
|
||||
|
||||
t.start();
|
||||
|
||||
System.out.println("Synchronzing");
|
||||
synchronized(TestObject.getSingleton()) {
|
||||
while(!TestObject.getSingleton().isInitialized) {
|
||||
System.out.println("Waiting for isInitialized");
|
||||
try {
|
||||
TestObject.getSingleton().wait(0);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
}//while//
|
||||
}//synchronized//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user