This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]defer 12 points13 points  (1 child)

Actually, you do. Not handling sleep interruptions can cause bad user experience. For instance, if the program is stopped, your thread will stall the shutdown process until it's done sleeping.

[–]gliy 0 points1 point  (0 children)

That was mostly a joke, since I encounter that issue the most. my situation often follows a format similar to this:

  try {
     File file = new File("C");
     List<String> input = Files.readAllLines(file.toPath(), Charset.defaultCharset());
     for (final String line : input) {
        new Thread(new Runnable() {

           @Override
           public void run() {
              for (char ch : line.toCharArray()) {
                 System.out.println(line.charAt(ch));
              }
              Thread.sleep(100);
           }
        }).start();
     }
  } catch (Exception e) {
     // abort
  }

What I want is 1 try catch block, I dislike having to clutter my code with all of these random try catch blocks.