Created
August 2, 2014 15:30
-
-
Save wicksome/6f81c443dd4672cc3eb1 to your computer and use it in GitHub Desktop.
데몬 쓰레드 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DaemonThread implements Runnable { | |
public static void main(String[] args) { | |
Thread th = new Thread(new DaemonThread()); | |
th.setDaemon(true); | |
th.start(); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Main thread terminated..."); | |
} | |
@Override | |
public void run() { | |
while (true) { | |
System.out.println("is running..."); | |
try { | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment