Is there a setting in the JME that I’m not seeing that is able to silence my errors in my program? There are literally NO catch statements in any of my classes yet it’s obvious when it runs into a bug because whatever linear tasks the program has running will drop. I’m so tired of having to tread around this so I’m asking you all for help.
So to sum it up:
Program runs into presumed error
Nothing prints in console
Subsequent tasks (such as println() statements) are ignored
It happens with things like for loops going into arrays (which makes me think I’m hitting an ArrayIndexOutOfBoundsException but I’m not 100% sure). When I remove those loops, subsequent tasks function fine.
So I figured out that it must have something to do with my Runnable because I attempted to load a model that I did not have in two areas of my program: one in the main method, which returned an error, and another within the Runnable which did not return an error (the program continued to run, just without anything from the Runnable).
When you use submit() it wraps your runnable in a Future and otherwise swallows all exceptions. With submit you are supposed to use the returned Future object to check for completion and exceptions.
Presuming your threedPool is a ThreadPoolExecutor then you should probably call execute() instead. Then at least you will get the default exception handling which should be to dump the stack trace to the console.
@pspeed said:
When you use submit() it wraps your runnable in a Future and otherwise swallows all exceptions. With submit you are supposed to use the returned Future object to check for completion and exceptions.
Presuming your threedPool is a ThreadPoolExecutor then you should probably call execute() instead. Then at least you will get the default exception handling which should be to dump the stack trace to the console.
I’ve replaced my one occurrence of submit() with execute() and I am still not receiving any exceptions. Are you able to demonstrate where I should place my execute() if I’m doing it wrong?
For debugging I’ve used a “try{}catch” inside my runnable to catch any exceptions and print them from the catch code.
That allowed my to find the exception and its cause, once the issue was fixed I removed the try-catch, not that there’d be an issue leaving it in.
So, if you run this code:
[java]
ExecutorService threadPool = Executors.newCachedThreadPool();
System.out.println(“Executing a test:”);
threadPool.execute(new Runnable() {
public void run() {
throw new RuntimeException(“Is this swallowed?”);
}
});
Thread.sleep(10000);
[/java]
…you don’t see anything printed to the console? Do you at least see the “Executing a test”?
If you don’t see the exception (and do see the println) then either some other piece of code (not JME) has overridden the default thread handler or your Java is very broken.
If you don’t even see the println then we’ve all been wasting our time because you are not seeing any printed output so of course you won’t see exceptions either.
I’m not sure if this changes much, but my threadpool is initialized outside of the class constructor with this line:
[java]
private final ScheduledThreadPoolExecutor threadpool = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
[/java]
@pspeed said:
So, if you run this code:
[java]
ExecutorService threadPool = Executors.newCachedThreadPool();
System.out.println("Executing a test:");
threadPool.execute(new Runnable() {
public void run() {
throw new RuntimeException("Is this swallowed?");
}
});
Thread.sleep(10000);
[/java]
…you don’t see anything printed to the console? Do you at least see the “Executing a test”?
If you don’t see the exception (and do see the println) then either some other piece of code (not JME) has overridden the default thread handler or your Java is very broken.
If you don’t even see the println then we’ve all been wasting our time because you are not seeing any printed output so of course you won’t see exceptions either.
I do see the println() statement but do not see the exception that’s supposed to be printed (this is with my current threadpool setup – it’s actually a ScheduledThreadPoolExecutor).
@mjbmitch said:
I'm not sure if this changes much, but my threadpool is initialized outside of the class constructor with this line:
[java]
private final ScheduledThreadPoolExecutor threadpool = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
[/java]
I do see the println() statement but do not see the exception that’s supposed to be printed (this is with my current threadpool setup – it’s actually a ScheduledThreadPoolExecutor).
Yep… too bad we had to wait until now to find this out. I should have asked explicitly instead of strongly hinting.
So, you have two choices:
don’t use scheduled thread pool executor… but I assume this is not an option since you probably want the scheduling.
do your own exception handling inside the run() method. Generally since scheduled thread pool executors don’t deal with constantly submitted random workers and likely deal with only 1 or a few specific worker tasks, then this is not really a problem.