mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
working on some threading issues
This commit is contained in:
@@ -988,7 +988,8 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
|
||||
Thread thread;
|
||||
|
||||
public RunButtonWatcher() {
|
||||
thread = new Thread(this);
|
||||
thread = new Thread(this, "run button watcher");
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ class PdeMessageSiphon implements Runnable {
|
||||
Thread thread;
|
||||
PdeMessageConsumer consumer;
|
||||
|
||||
public PdeMessageSiphon(InputStream stream, PdeMessageConsumer consumer) {
|
||||
|
||||
public PdeMessageSiphon(InputStream stream, PdeMessageConsumer consumer) {
|
||||
// we use a BufferedReader in order to be able to read a line
|
||||
// at a time
|
||||
//
|
||||
@@ -39,40 +39,62 @@ class PdeMessageSiphon implements Runnable {
|
||||
this.consumer = consumer;
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
while (Thread.currentThread() == thread) {
|
||||
//System.err.print("p");
|
||||
//System.err.println(streamReader);
|
||||
String currentLine;
|
||||
//while (Thread.currentThread() == thread) {
|
||||
//System.err.print("p");
|
||||
//System.err.println(streamReader);
|
||||
String currentLine;
|
||||
|
||||
try {
|
||||
// process data until we hit EOF; this may block
|
||||
//
|
||||
while ((currentLine = streamReader.readLine()) != null) {
|
||||
consumer.message(currentLine);
|
||||
//System.err.println("PMS: " + currentLine);
|
||||
try {
|
||||
// process data until we hit EOF; this will happily block
|
||||
// (effectively sleeping the thread) until new data comes in.
|
||||
// when the program is finally done,
|
||||
//
|
||||
while ((currentLine = streamReader.readLine()) != null) {
|
||||
//currentLine = streamReader.readLine();
|
||||
//if (currentLine != null) {
|
||||
consumer.message(currentLine);
|
||||
//System.out.println("siphon wait");
|
||||
}
|
||||
/*
|
||||
if (currentLine == null) {
|
||||
System.out.println("PdeMessageSiphon: out");
|
||||
thread = null;
|
||||
}
|
||||
} catch (NullPointerException npe) {
|
||||
// ignore this guy, since it's prolly just shutting down
|
||||
//npe.printStackTrace();
|
||||
*/
|
||||
thread = null;
|
||||
//System.err.println("PMS: " + currentLine);
|
||||
//}
|
||||
|
||||
} catch (NullPointerException npe) {
|
||||
// ignore this guy, since it's prolly just shutting down
|
||||
//npe.printStackTrace();
|
||||
thread = null;
|
||||
|
||||
} catch (Exception e) {
|
||||
// on linux, a "bad file descriptor" message comes up when
|
||||
// closing an applet that's being run externally.
|
||||
// use this to cause that to fail silently since not important
|
||||
if ((PdeBase.platform != PdeBase.LINUX) ||
|
||||
(e.getMessage().indexOf("Bad file descriptor") == -1)) {
|
||||
System.err.println("PdeMessageSiphon err " + e);
|
||||
e.printStackTrace();
|
||||
thread = null;
|
||||
|
||||
} catch (Exception e) {
|
||||
// on linux, a "bad file descriptor" message comes up when
|
||||
// closing an applet that's being run externally.
|
||||
// use this to cause that to fail silently since not important
|
||||
if ((PdeBase.platform != PdeBase.LINUX) ||
|
||||
(e.getMessage().indexOf("Bad file descriptor") == -1)) {
|
||||
System.err.println("PdeMessageSiphon err " + e);
|
||||
e.printStackTrace();
|
||||
thread = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.err.println("siphon thread exiting");
|
||||
|
||||
/*
|
||||
//Thread.yield();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) { }
|
||||
*/
|
||||
//System.out.println("PdeMessageSiphon: out");
|
||||
}
|
||||
//System.err.println("siphon thread exiting");
|
||||
}
|
||||
|
||||
@@ -24,17 +24,11 @@
|
||||
|
||||
import processing.core.*;
|
||||
|
||||
import java.awt.*; // for window
|
||||
import java.awt.event.*; // also for window
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
//#ifndef RXTX
|
||||
//import javax.comm.*;
|
||||
//#else
|
||||
//import gnu.io.*;
|
||||
//#endif
|
||||
|
||||
|
||||
public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
@@ -94,25 +88,26 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
windowLocation.x + "," + windowLocation.y) :
|
||||
(PApplet.EXT_LOCATION + x1 + "," + y1);
|
||||
|
||||
//java "-Djava.library.path=C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems\code" -cp "lib\build;java\lib\rt.jar;lib;lib\build;lib\pde.jar;lib\core.jar;lib\mrj.jar;lib\antlr.jar;lib\oro.jar;C:\WINDOWS\system32\QTJava.zip;;C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems\code" processing.core.PApplet --location=710,61 "--sketch-folder=C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems" Temporary_6879_7583
|
||||
String command[] = new String[] {
|
||||
"java",
|
||||
"-Djava.library.path=" + sketch.libraryPath, // might be ""
|
||||
"-cp",
|
||||
sketch.classPath,
|
||||
"processing.core.PApplet",
|
||||
//PApplet.EXTERNAL_FLAG + location,
|
||||
location,
|
||||
PApplet.EXT_SKETCH_FOLDER + sketch.folder.getAbsolutePath(),
|
||||
sketch.mainClassName
|
||||
};
|
||||
|
||||
//PApplet.println(command);
|
||||
//PApplet.println(PApplet.join(command, " "));
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
new PdeMessageSiphon(process.getErrorStream(), this);
|
||||
new SystemOutSiphon(process.getInputStream());
|
||||
//new PdeMessageSiphon(process.getErrorStream(), this);
|
||||
new PdeMessageSiphon(process.getErrorStream(), this);
|
||||
processOutput = process.getOutputStream();
|
||||
|
||||
} else {
|
||||
} else { // !externalRuntime
|
||||
//Class c = Class.forName(className);
|
||||
Class c = Class.forName(sketch.mainClassName);
|
||||
applet = (PApplet) c.newInstance();
|
||||
@@ -525,31 +520,60 @@ java.lang.NullPointerException
|
||||
this.input = input;
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
byte boofer[] = new byte[1024];
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
//int count = input.available();
|
||||
//int offset = 0;
|
||||
while (Thread.currentThread() == thread) {
|
||||
// read, block until something good comes through
|
||||
//if (input.available() > 0) {
|
||||
try {
|
||||
int count = input.read(boofer, 0, boofer.length);
|
||||
if (count == -1) break;
|
||||
System.out.print(new String(boofer, 0, count));
|
||||
}
|
||||
//System.out.print("bc" + count + " " + new String(boofer, 0, count));
|
||||
|
||||
|
||||
/*
|
||||
int c;
|
||||
while ((c = input.read()) != -1) {
|
||||
System.out.print((char) c);
|
||||
} catch (IOException e) {
|
||||
thread = null;
|
||||
}
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
System.err.println("SystemOutSiphon error " + e);
|
||||
e.printStackTrace();
|
||||
//System.out.println("SystemOutSiphon: out");
|
||||
//thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//while (Thread.currentThread() == thread) {
|
||||
//try {
|
||||
//while (true) {
|
||||
//int count = input.available();
|
||||
//int offset = 0;
|
||||
int count = input.read(boofer, 0, boofer.length);
|
||||
if (count == -1) {
|
||||
System.out.println("SystemOutSiphon: out");
|
||||
thread = null;
|
||||
}
|
||||
//if (count != -1) {
|
||||
if (count > 0) {
|
||||
System.out.print(new String(boofer, 0, count));
|
||||
}
|
||||
//}
|
||||
//}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("SystemOutSiphon error " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Thread.yield();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) { }
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1526,6 +1526,7 @@ public class PApplet extends Applet
|
||||
gimmeImage(getClass().getResource("data/" + filename), force);
|
||||
}
|
||||
if (awtimage == null) {
|
||||
/*
|
||||
try {
|
||||
//FileInputStream fis =
|
||||
//new FileInputStream(folder + "data/" + filename);
|
||||
@@ -1534,6 +1535,7 @@ public class PApplet extends Applet
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (awtimage == null) {
|
||||
@@ -2764,6 +2766,7 @@ public class PApplet extends Applet
|
||||
|
||||
Thread thread = new Thread() { //new Runnable() {
|
||||
public void run() {
|
||||
|
||||
while ((Thread.currentThread() == this) && !finished) {
|
||||
try {
|
||||
// is this what's causing all the trouble?
|
||||
@@ -2845,6 +2848,7 @@ public class PApplet extends Applet
|
||||
name = args[argIndex];
|
||||
break;
|
||||
}
|
||||
argIndex++;
|
||||
}
|
||||
|
||||
Frame frame = new Frame();
|
||||
|
||||
Reference in New Issue
Block a user