public void run() { System.out.println("System has entered running mode"); while (threadCheck) { System.out.println("O.K. see how we execute target program"); this.generatePdf(MNo); try { System.out.println("Right, let's wait for task to complete of fail"); java.lang.Thread.currentThread().sleep(200); System.out.println("It's time for us threads to get back to work after the nap"); } catch (java.lang.InterruptedException IntExec) { System.out.println(IntExec.getMessage()); } threadCheck = false; System.out.println("We shall be lucky to get back to start in one piece"); } if (!threadCheck) { Thread.currentThread().stop(); } }
/** * Gives the same basic functionality of File.exists but can be used to look for removable media * without showing a system dialog if the media is not present. Workaround pulled from the <A * HREF="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4089199"> bug report</A> on * bugs.sun.com. This bug was fixed in Java 6, and we can remove the workaround when we start * requiring Java 6. */ protected static boolean fileExists(File file) { try { Process process = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "dir", file.getAbsolutePath()}); // We need to consume all available output or the process will block. boolean haveExitCode = false; int exitCode = -1; InputStream out = process.getInputStream(); InputStream err = process.getErrorStream(); while (!haveExitCode) { while (out.read() >= 0) {} while (err.read() >= 0) {} try { exitCode = process.exitValue(); haveExitCode = true; } catch (IllegalThreadStateException e) { // Not yet complete. Thread.sleep(100); } } // int exitCode = process.waitFor(); return exitCode == 0; } catch (IOException e) { System.out.println("Unable to check for file: " + file + " : " + e); return false; } catch (InterruptedException e) { System.out.println("Unable to check for file. Interrupted: " + file + " : " + e); return false; } }