Thread start in Static Initialization Blocks


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public class ThreadDemo {
  2. private static Logger logger = Logger.getLogger(ThreadDemo.class.toString());
  3.  
  4. static {
  5. new Thread(new Runnable() {
  6. public void run() {
  7.  
  8. while (true) {
  9. try {
  10. Thread.sleep(100L);
  11. } catch (InterruptedException e) {
  12. logger.fine("Interrupted : " + e.getMessage());
  13. }
  14. logger.info("job");
  15. }
  16. }
  17. }).start();
  18. }
  19.  
  20. public static void main(String[] args) {
  21. logger.info("start");
  22. }
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.