I have a really weird problem that I cannot find a solution for. I have a Java class that extends Thread. I instantiate it (from a thread form a ThreadPoolExecutor
) and run start()
. However, the execution just hangs and never returns from the constructor, despite its first statement not being run.
Here's the only constructor declared in the class:
public class Recorder extends Thread{
private String channelId;
private RecorderCallback recorderCallback;
public Recorder(String channelId, String workingDirectory, RecorderCallback RecorderCallback){
//super();
try{
System.out.println(getCurrentTimeStamp() + " DEBUG new recorder: " + channelId + " | " + workingDirectory);
this.channelId = channelId;
String timeString = new SimpleDateFormat("dd.MM.yyyy-HHmmss").format(new Date());
this.directory = timeString + "_" + channelId;
new File(workingDirectory + File.separator + directory).mkdirs();
} catch (Exception exception){
System.out.println(getCurrentTimeStamp() + " An unexpected exception occurred: " + exception.getMessage());
exception.printStackTrace();
} finally {
System.out.println(getCurrentTimeStamp() + " DEBUG FINALLY called in CONSTRUCTOR");
}
}
Here's the point where I initialize and run a new Recorder
(which is NOT wrapped in a try/catch block and the method this code is in isn't declared to throw any exceptions):
System.out.println(getCurrentTimeStamp() + " Creating new recorder [" + channelId + "]");
Recorder recorder = new Recorder(channelId, Constants.RECORDING_WORKING_DIR, this);
System.out.println(getCurrentTimeStamp() + " DEBUG Instance created"));
recorder.start();
When I run the application, I get this trace:
[timestamp] Creating new recorder [channelname]
No other output at all. I'm using OpenJDK 1.8.0_242.
Is the problem that the print just isn't processed? What am I missing?