• Tidak ada hasil yang ditemukan

Thus to cause the thread to execute from a class that implements Runnable you would call the following

N/A
N/A
Protected

Academic year: 2018

Membagikan "Thus to cause the thread to execute from a class that implements Runnable you would call the following"

Copied!
10
0
0

Teks penuh

(1)

!

" !

# $

%&

' ( ) !

%*%++

! ' &

' $

$ $

,

' *

,

- ! . ,

'

/ )

( 0

1 0

class MyClass implements Runnable{

public void run(){

// Insert the code you want to run in a thread here }

(2)

0

'

$ $

! $

)

class MyThread extends Thread { public void run () {

// Insert the code you want to run in a thread here }

}

'

0

- . 0

Thus to cause the thread to execute from a class that implements Runnable you would call the

following

MyClass mc = new MyClass(); Thread t = new Thread(mc); t.start();

Although it is the run method code that executes, a thread is actually started via the start method

MyClass mc = new MyClass(); MyClass mc2 = new MyClass(); Thread t = new Thread(mc); Thread t2 = new Thread(mc2); t.start();

(3)

2 ( 2 3

0 ,

(4)

!

"

4

• 5 ! %&

-' 6 .

• ! "

o -. 5 % - .

)

o 5 % )

o ) -. 5 !

(5)

$

#

$

" %

%

"

"

7

% & " ' ( " )

)

7 ,

)

synchronized void someMethod() { }

8 7 7

) 4

// .. some code before the synchronized block synchronized (someObject) {

// synchronized code }

// more code...

*+ ,

-. 7

) "

-0 . -. -.

5

*+ - *+ , (

-. ) 0

9

(6)

.

public synchronized void push(char c); public synchronized char pop();

(7)

/

12 }

2<< < =<<

3 >

8

7 ? !

0 0 "

: : ) ; 8

4

public class SyncStack {

private List buffer = new ArrayList(400); public synchronized char pop() {...}

public synchronized void push(char c) {...} }

7

! >

4

1 public synchronized char pop() { 2 char c;

3 while (buffer.size() == 0) { 4 try {

5 this.wait();

6 } catch (InterruptedException e) { 7 // ignore it...

8 } 9 }

10 c = ((Character)buffer.remove(buffer.size()-1)).charValue(); 11 return c;

12 }

) 7

)

* ;

7 @

: -. 7

(8)

1

public synchronized void push(char c) { this.notify();

Character charObj = new Character(c); buffer.addElement(charObj);

1 package mod13; 2

3 public class SyncTest { 4

(9)

3

24 } 25 }

& ) 4

1 package mod13; 2

3 public class Producer implements Runnable { 4 private SyncStack theStack;

5 private int num;

1 package mod13; 2

3 public class Consumer implements Runnable { 4 private SyncStack theStack;

5 private int num;

(10)

: : ) 4

1 package mod13; 2

3 import java.util.*; 4

5 public class SyncStack {

6 private List buffer = new ArrayList(400); 7

17 c = ((Character)buffer.remove(buffer.size()-1)). 18 charValue();

19 return c; 20 }

21

22 public synchronized void push(char c) { 23 this.notify();

24 Character charObj = new Character(c); 25 buffer.addElement(charObj);

26 } 27 }

) C= : 3

Referensi

Dokumen terkait

Bahasan berikut akan mencakup berbagai ha1 yang terkait dengan keselamatan dan kesehatan kerja dan pada bagian akhir akan dibicarakan secara ringkas bentuk-bentuk

Dari hasil penelitian dan pengolahan data yang telah dilakukan dapat ditarik kesimpulan bahwa variabel ekuitas merek berpengaruh positif dan signifikan terhadap rasa percaya

Dari hasil uji coba pencarian data pasal yang telah dilakukan, maka didapatkan hasil bahwa algoritma Boyer-Moore yang diaplikasikan ke dalam aplikasi sistem pendukung

Based on the results of an interview with one of the students majoring in Electrical Engineering Faculty of Engineering, State University of Padang, before getting a letter they

dikhususkan oleh ‘urf. Seperti sholat, zakat, puasa dan haji. Untuk ‘urf al -amali terjadi perbedaan pendapat ulama‟ Hanafiah jika ‘urf al -amali bersifat umum, maka

ANALISIS PENGARUH RASIO LIKUIDITAS, LEVERAGE , PROFITABILITAS DAN MARKET VALUE ADDED TERHADAP RETURN SAHAM (Studi kasus pada Perusahaan Indeks LQ 45 Yang

a) Guru merancang program pembelajaran. b) Dalam aplikasi pembelajaran di kelas, guru merancang lembar observasi yang akan digunakan untuk mengobservasi kegiatan peserta didik

Misalkan pas seandaine mau tidur dibilangi ada masalah apa dan misalkan saya yang salah, misalkan ada kata-kata yang tidak baik atau yang tidak sesuai gitu saya sama istri