|
||
0
0
À̶óÀ̳Ê
mutex ÀÌ¿ëÇÏ¸é µÇÁö ¾ÊÀ»±î¿ä?
2018-07-03
|
0
0
Çö´ëI30
ÀÚ´äÀÔ´Ï´Ù
package Timer2; public class Timer2 { public static boolean pause = false; public static int period = 5000; public static int count = period / 1000; public static void main(String[] args) { TimerThread2 timer = new TimerThread2(); timer.start(); Runnable btnR = new Button(timer); Thread btnTh = new Thread(btnR); btnTh.start(); } } class TimerThread2 extends Thread { @Override public void run() { while (true) { System.out.println("µ¥ÀÌÅÍ Àü¼Û : µ¥ÀÌÅÍ ¤¡¤¡¤¶"); while (Timer2.count > 0) { try { System.out.println("Count : " + Timer2.count); Thread.sleep(1000); synchronized (this) { while (Timer2.pause == true) { wait(); } } } catch (InterruptedException e) { e.printStackTrace(); } --Timer2.count; if (Timer2.count == 0) { Timer2.count = Timer2.period / 1000; break; } } } } // ÀϽÃÁ¤Áö public void Pause() { Timer2.pause = true; } public synchronized void Continue() { Timer2.pause = false; notify(); } }
2018-07-03
|
0
0
ÀÚ·»
wait notify µµ ÀÖ¾î¿ä ±×³É ±âº»±â´ÉÀÌ¿¡¿ä
2018-07-10 *
|
|
|
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û | -¸ñ·Ïº¸±â |