java:concurrency_intro
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
java:concurrency_intro [2017/03/19 17:47] – [Σταματώντας προσωρινά την εκτέλεση ενός νήματος μέσω της μεθόδου sleep()] gthanos | java:concurrency_intro [2018/03/08 10:37] (current) – [Εφαρμόζοντας τις μεθόδους sleep()/interrupt()/join() σε ένα παράδειγμα] gthanos | ||
---|---|---|---|
Line 49: | Line 49: | ||
<code java SleepMessages.java> | <code java SleepMessages.java> | ||
public class SleepMessages { | public class SleepMessages { | ||
- | | + | |
- | throws InterruptedException { | + | throws InterruptedException { |
- | String importantInfo[] = { | + | String importantInfo[] = { |
- | "Mares eat oats", | + | "Peter Pan", |
- | "Does eat oats", | + | "leader of the Lost Boys", |
- | "Little lambs eat ivy", | + | "goes to Neverland" |
- | "A kid will eat ivy too" | + | }; |
- | }; | + | |
- | | + | |
- | //Pause for 2 seconds | + | //Pause for 2 seconds |
- | Thread.sleep(2000); | + | Thread.sleep(2000); |
- | //Print a message | + | //Print a message |
- | System.out.println(importantInfo[i]); | + | System.out.println(importantInfo[i]); |
- | } | + | |
} | } | ||
+ | } | ||
} | } | ||
</ | </ | ||
Line 72: | Line 71: | ||
</ | </ | ||
- | ===== Επανενεργοποίηση ενός νήματος μέσω της μεθόδου interrupt() ===== | + | ===== Αφύπνιση ενός νήματος μέσω της μεθόδου interrupt() ===== |
Μία διακοπή (// | Μία διακοπή (// | ||
Line 80: | Line 79: | ||
Thread.sleep(4000); | Thread.sleep(4000); | ||
} catch (InterruptedException e) { | } catch (InterruptedException e) { | ||
- | System.out.println((" | + | System.out.println(" |
return; | return; | ||
} | } | ||
Line 210: | Line 209: | ||
}</ | }</ | ||
- | + | |Προηγούμενο: | |
- | + | ||
- | + | ||
- | + |
java/concurrency_intro.1489945628.txt.gz · Last modified: 2017/03/19 17:47 by gthanos