+ All Categories
Home > Documents > Jurnal Crp Blok Gis Sem V

Jurnal Crp Blok Gis Sem V

Date post: 28-Nov-2015
Category:
Upload: santa-yo
View: 32 times
Download: 0 times
Share this document with a friend
21
1 2 ! " " !! # $ %$ $
Transcript
Page 1: Jurnal Crp Blok Gis Sem V

1

��������������� �������������� ��� �����

���������������� ������������������ ���������

�������������

2

� ������������������� ����� ������������������������� ���!����������������

� �������������"�������"������������� ��������!!����������������������������������� ��������������������������������������

� #���� �������$�� %������$�� ����������$�

Page 2: Jurnal Crp Blok Gis Sem V

3

��� ���� ���������������

� ����������������"�!������������������������ ��������������� �����!����������� �������� ��������������������"��� �

� &����� ��������������������"��� �� %'��(%������'�!�������)� �����

� *��������������"�!���������������������������!����� ��������� ������!� �������!�+���

� �����,� - ������%.+/�+0*� 1��2� &�2�(��!������3*&0��&�2����������)

4

������� ����� ��� ������ *������������������"��� ������������������"�!���������������������������!����� ���������!���������

� 4������ ��������������� ���������"������"�!������������������������!���� ��������������������� 4��������"�!�����������������������"�� 4�����"�!������ ������ �����������������������

� ��!��������������� ������������������������ ����� ������������

� ������������������!��������!������������!�����������!����������������������������� �!�������������������������������� ������� �������������������������!�����"����!���������

� �����,�4�����

Page 3: Jurnal Crp Blok Gis Sem V

5

�������������

Applications, services

Computer &

Platform

Middleware

OS: kernel,libraries & servers

network hardware

OS1

Computer & network hardware

Node 1 Node 2

Processes, threads,communication, ...

OS2Processes, threads,communication, ...

6

���������������

� 5��� �������%$���������!������������������������ ����������������������������������������������"��� �

� �������������� ������!����������!����������!������������ �����������

� ����������!������������������������������������������

� �������� ��!��� ������������������ ��������� ���������"���

� ��������� ���������� *��������� �����������������������������������������������������

Page 4: Jurnal Crp Blok Gis Sem V

7

���������������

� ������� �������� ����!�������������(���������������)

� ����� �������� ���������������6�������������!�

� ���������� �������� �������������������

� *������������� ��������� *�������������� ��������

� ������ �������� �� ���������������������������7����!

� �������� ������������ *� ����������������"������������!!�����2������ ����!�������"����������������������������� �����!������ �������������

8

��������� ����� � ����� ������������������������

� ��������������������������������������������������������� �����,����������!�������&%80+1��2��������������"�������������������������������������!���� ���������!����������������� �!��

� ! ��� �� ���������������������� �����!����������!� ��������������� ���������

� ��������������,������������������!������ ����!��������������� ������������!��� �������������������������� �������������� �����!��������!������������� *������������������ ������!���������������!����������� �������

� *������������������������������������������������ ������

Page 5: Jurnal Crp Blok Gis Sem V

9

� ���� *�����,�*�� ������ ����� ���"�!���� �����������!��������������������� ��������!����������������� ������� ���������

� ������� ������ ���������������������������������������(�����,�������������������������� �������)

� ������������������(�������������������������)� �������

� ����������������������!��������������� ����!��������������������������������������� ������������!�������������� �����������+��������������!������������ ���7���,����������������� �����������9�����!������������9������� ����!������������

� ����������7���������� ����������!������������ ��� ��(:!� ���� �;)

10

� ��������� ��

� 4�����������(������� �����)��������������������������������!��������������!����

� ��"�� &���������� .������ �������������������

� #� *��������!�������!���������

� � � �� ����� *������7����!������������!������������������������������ ��������

� ���� ������������������<�������

Stack

Text

Heap

Auxiliaryregions

0

2�

Page 6: Jurnal Crp Blok Gis Sem V

11

��������� ���� *������������������������������ ����� �����������������������������������

� ���� ��������,������ �����&%80���������������������������� ��!� �� ������������� �������!������������� �!������� �����&%80���������� ��7������������������� ����� �!������!������������������� ����

� &����������������������������������������!��������������� ���������������������������������� ����������� ������� �!���������������� ����"�������������!����������������

� *����������������������� ����"����/������� *���!���������� ����"�� *�������!� �� ����������

12

��������� ���$����� ���%�����&���

� 4!���������������!����������������������������!��������������������!����������������������������� �������� ������������������(�!����� )

� *� �!������������������������������������������"����(�����)�,� �������� �������������������������������������������������!���!�����"�����"�����8����������� �� �����������!���!���������������

� ������ ������������������������ ���"�!������������� �����!������ ��������������������������!������������������(4�<=��)����������������(4�������� �����������>�?)��4����7����!������������������������������������������!��������������������������������������� �������������������������������� ��� ���������������������

Page 7: Jurnal Crp Blok Gis Sem V

13

������ � ��������

� ����������� ������� � ����

� 4����������� ���������� ��� ����!�������������� ���������� ������������� �!�������������������������������

� 3������� 4���������������� ������� �� ����������!��������������

� ������!������ %������������������������������!����������!� �� ���������������������!�����

14

'��� ���������� � ���

� ��� (������� %������ ����������������������������������� � �"����������� ����!�����������������

� ����<�������������������������!���������������!�����������"�������������!�����������

� )"�* (������� %������ ���������"��������������������������������������������������!�������� �������� �����!�������������������������������������������������

� ����������!������������������������������� ����� ���� ����

� *���������������������������������������� ������

Page 8: Jurnal Crp Blok Gis Sem V

15

��������� ���$�������������������+������

� ����������������������!����������������������������!� �� �������������� ����������������������������� ���!������!������"� �����������!������������!��������

� 4��������������������������������������!������������������������������������,� 8����!���������� � �������!���������� ����� ���������������������������������

� �����,��������fork������&�2,�����������!������� ���2��� ����� ������������!�����������������������

� ����<�������(������������������)� ���������������� ��� ���������������� ���������� �� ��������� ������������@� 4�������� ����� ������������������������ �����������@

16

,���(���- �

Page 9: Jurnal Crp Blok Gis Sem V

17

,���(���- �� �� ����4������������������������� ������������������� �����������<�����������������������4�����

� ������������������4��� ������ ����4���������A����<�������A��!������������(����������!�)������ ���� ��������������!�����������

� *� ��������� ���4�������������������������� ��������(����������������������� ���� ��7����!�������)�������� ���4����������������������������������/��� ����!����������*� �����������!��� ����������!����

� #�����������������������!��������������� �������������������������!������� ������� ����������� �!�������� ��������������� ������!������������� ����������!������� ��4�������������!� ��!��

18

� ��

� *������ ��� �������������,

� ���7�������!�������!���������!����������

Page 10: Jurnal Crp Blok Gis Sem V

19

� ���������.�&��� &�$�����������)/���� *

� �������� ,�/���� 8$���!���(������� ),�B���� �� !�������� CD����������9������CDD���9��������������

� ����������(������� )� B����������9�����C/E���9��������������

� ������������������ � FEG�������� ����8$�����������9���,�D�/E�H�B���I�/��

� EDD���9��������������� ����������������� �����������9���,�/�E���

� JDD���9��������������

20

� �������� *

� - ������*��!� ������ �����������������!�������������"�������7������� ���!����

� ���� �����������"� ���������������� .������������9���

� .������A�����A��������!������!�����������9���� ���������!������������(�������������)� ����������A�����A������������������������� ������������

Page 11: Jurnal Crp Blok Gis Sem V

21

� �������� * � .����������������

� .����������������������������������� ����� ���!����!������������������"�����!�������������� �

� �!����������!������������������������ ��������������������

� .������������"��� .������������������������"��������� #�������������������������������"��������������

22

� ���*������� �"��� *���������������������������������� �!���������!������������������!� �� ���������������� *�����������������

� ���!���������� ������������������ *������������������

� ���!����������������������������������������� *�������������������!������������������������������������������ ������������������������ ���"�!������������� �� ������� �������� ��������������������"�������2�������

� ��!� ����������������������!�����������"������!�������!� �� ������������������

� .������������!��� ������������������ ��������!���

Page 12: Jurnal Crp Blok Gis Sem V

23

�� �� ������ ��� Dalam satu aplikasi dapat berjalan proses thread lebih dari

satu, dan semua thread menggunakan space address memori yang sama, sehingga satu thread dengan thread lain dalam satu program dalam saling berbagi public instance variabel.

� Oleh karena banyak thread dapat mengakses public instance variable, maka antara satu thread dengan thread lainnya harus ada synchronization.

� Java mendukung pemrograman banyak thread, yang dikenal dengan multithreading.

24

Java Thread� Sebuah thread mulai dibuat, ketika dilakukan pembuatan

objek baru dari class java.lang.Thread.

� Sebuah objek Thread, mewakili thread sesungguhnya dalam intepreter Java dan juga memberikan penanganan kontrol dan sinkronisasi eksekusinya

� Sebuah objek yang akan diperlakukan sebagai sebuah thread, harus menerapkan dari sebuah interface java.lang.Runnable. Interface Runnable menyediakan satu method kunci, yaitu run().

public interface Runnable { abstract public void run(); } � Sebuah thread dimulai "siklus hidupnya" dengan memanggil

method run().

Page 13: Jurnal Crp Blok Gis Sem V

25

� Untuk membuat sebuah class yang akan bertindak sebagai sebuah thread, definisikan dengan sintak berikut

class NamaClass implements Runnable { void run() { //kode program yang dikerjakan }}� Cara memanggil class thread tersebut :

� Buat instance objek dari class Runnable tersebut� Buat objek dari class java.lang.Thread dengan parameter

constructor objek dari class Runnable� Panggil method start() dari objek Runnable.

� Contoh class sebagai implemen dari Runnable:class MyThread implements Runnable { private static int i = 0; public void run() { while (i<100) { System.out.print(i + ", "); i++; } }}

26

� Dan berikut contoh pemanggilan class MyThread :

01 public class MyThread1 {02 public static void main(String[] args) {03 MyThread oThread = new MyThread();04 Thread myTh = new Thread(oThread);05 myTh.start();0607 for(int j=0; j<10; j++) {08 System.out.println("from main " + j);09 }10 }11 }� Pembuatan objek dari class Thread harus menyebutkan suatu

class yang diimplementasikan dari interface Runnable pada parameter constructornya. Lihat baris ke 5.

� Untuk memulai siklus hidup suatu thread, method start() harus dipanggil, yang secara otomatis akan memanggil method run() yang telah didefinisikan pada class implements Runnable.

Page 14: Jurnal Crp Blok Gis Sem V

27

� Contoh lain:

class MyThread implements Runnable { private static int i = 0; Thread myTh;

public MyThread() { myTh = new Thread( this ); myTh.start(); }

public void run() { while (i<100) { System.out.print(i + ", "); i++; } }}� Latihan! Tuliskan method main() untuk menjalankan thread

MyThread tersebut!

28

� Teknik lain adalah dengan membuat class turunan dari class lain yang telah menerapkan Runnable.

� Class Thread merupakan class yang implements dari interface Runnable. Perhatikan contoh berikut :

class thFromThread extends Thread { private static int i = 0;

public void run() { while (i<100) { System.out.print(i + ", "); i++; } }}

� Latihan! Tuliskan method main() untuk menjalankan thread thFromThread tersebut!

Page 15: Jurnal Crp Blok Gis Sem V

29

� Percobaan!!!

class MyThread implements Runnable { private static int i = 0; private String name;

public MyThread(String a) { name = a; }

public void run() { while (true) { System.out.println("From " + name + " = " + i);

i++; } }}

...

30

public class MyThread4 { public static void main(String[] args) { MyThread oThread = new MyThread("oThread"); MyThread oThread2 = new MyThread("oThread2"); Thread myTh = new Thread(oThread); Thread myTh2 = new Thread(oThread2); myTh.start(); for(int j=0; j<100; j++) ; myTh2.start(); }}

� Contoh hasil :...

From oThread = 8366

From oThread = 8367

From oThread = 8368

From oThread2 = 8369

From oThread = 8370

From oThread2 = 8371

From oThread = 8372

From oThread2 = 8373

From oThread = 8374

From oThread2 = 8375

...

Page 16: Jurnal Crp Blok Gis Sem V

31

� Method start() digunakan untuk memulai sebuah thread dieksekusi.

� Method stop() digunakan untuk menghentikan eksekusi suatu thread.

� Method suspend() digunakan untuk menghentikan sementara waktu (pause) untuk kemudian dapat dilanjutkan kembali dengan memanggil method resume().

� Jika beban yang harus dikerjakan oleh thread berat/mahal, maka dapat digunakan method suspend() dan resume().

� Method static sleep(n_msec) digunakan untuk menghentikan thread yang aktif selama n milisecond.

try { Thread.sleep ( 1000 ); } catch ( InterruptedException e ) { } � Method start() dan stop() hanya dapat dipanggil sekali untuk semua

thread.

Pengontrolan Thread

32

� Percobaan sleep()

class MyThread implements Runnable { private static int i = 0; public void run() { while (i<100) { System.out.print(i + ", "); i++; } }}public class MyThread5 { public static void main(String[] args) { MyThread oThread = new MyThread(); Thread myTh = new Thread(oThread); myTh.start(); for(int j=0; j<10; j++) { if (j == 5) { try { myTh.sleep(1000); } catch (InterruptedException e) { } } System.out.println("from main " + j); } }}

Page 17: Jurnal Crp Blok Gis Sem V

33

� Contoh hasil run time:from main 0

from main 1

from main 2

from main 3

from main 40, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,

20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,

37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,

54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,

71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,

88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,

from main 5

from main 6

from main 7

from main 8

from main 9

34

� Percobaan suspend() dan resume()

class MyThread implements Runnable { private static int i = 0; public void run() { while (true) { i++; } } public int geti() { return i; }}

Page 18: Jurnal Crp Blok Gis Sem V

35

public class MyThread6 { public static void main(String[] args) { boolean isSuspend = false;

MyThread oThread = new MyThread(); Thread myTh = new Thread(oThread); myTh.start(); for(int j=1; j<10000; j++) { if (j % 250 == 0) { if (isSuspend) { myTh.resume(); System.out.println("after resume() i is " + oThread.geti());

} else { myTh.suspend(); System.out.println("after suspend() i is " + oThread.geti());

} isSuspend = !isSuspend; } } myTh.stop(); }}

36

� Contoh hasil run time:

after suspend() i is 0

after resume() i is 26314152

after suspend() i is 66298778

after resume() i is 66298778

after suspend() i is 66298778

after resume() i is 66298778

after suspend() i is 87277096

after resume() i is 87277096

after suspend() i is 87277096

after resume() i is 87277096

after suspend() i is 106409413

after resume() i is 106409413

after suspend() i is 106409413

after resume() i is 106409413

after suspend() i is 125764431

after resume() i is 125764431

...

Page 19: Jurnal Crp Blok Gis Sem V

37

� Pada kenyataannya nanti, kita mungkin akan menggunakan beberapa thread untuk mengakses resource yang sama.

� Untuk menghindari masalah pada saatu pengaksesan resource yang sama antar thread, maka satu thread harus tahu akan thread yang lain. Ini yang disebut synchronization.

� Berikut adalah contoh jika tanpa menggunakan synchronization:

Synchronization

38

public class Producer extends Thread { private CubbyHole cubbyhole; private int number;

public Producer(CubbyHole c, int number) { cubbyhole = c; this.number = number; } public void run() { for (int i=0; i < 10; i++ ) { cubbyhole.put(i); System.out.println("Producer #" + this.number + " put:" + i);

try { sleep((int)(Math.random() * 100)); } catch (InterruptedException e) { } } }}

Page 20: Jurnal Crp Blok Gis Sem V

39

public class Consumer extends Thread { private CubbyHole cubbyhole; private int number; public Consumer(CubbyHole c, int number) { cubbyhole = c; this.number = number; }

public void run() { int value = 0; for (int i=0; i<10; i++) { value = cubbyhole.get(); System.out.println("Consumer #" + this.number + " got:"+value);

try { sleep((int)(Math.random() * 100)); } catch (InterruptedException e) {} } }}

40

public class CubbyHole { private int contents; private boolean available = false; public int get() { return contents; }

public void put (int value) { contents = value; }}

public class ProducerConsumerTest { public static void main(String args[]) { CubbyHole chole = new CubbyHole(); Producer p1 = new Producer(chole, 1); Consumer c1 = new Consumer(chole, 1); p1.start(); c1.start(); }}

Page 21: Jurnal Crp Blok Gis Sem V

41

contoh hasil :

Producer #1 put:0Consumer #1 got:0Producer #1 put:1Consumer #1 got:1Consumer #1 got:1Producer #1 put:2Consumer #1 got:2Producer #1 put:3Consumer #1 got:3Producer #1 put:4Consumer #1 got:4Producer #1 put:5Producer #1 put:6Consumer #1 got:6Producer #1 put:7Consumer #1 got:7Producer #1 put:8Consumer #1 got:8Consumer #1 got:8Producer #1 put:9

42

public class CubbyHole { private int contents; private boolean available = false; public synchronized int get() { while (available == false) { try { wait(); } catch(InterruptedException e) {} } available = false; notifyAll(); return contents; }

public synchronized void put (int value) { while (available == true) { try { wait(); } catch(InterruptedException e) {} } contents = value; available = true; notifyAll(); }}

contoh hasil :

Producer #1 put:0Consumer #1 got:0Producer #1 put:1Consumer #1 got:1Producer #1 put:2Consumer #1 got:2Producer #1 put:3Consumer #1 got:3Producer #1 put:4Consumer #1 got:4Producer #1 put:5Consumer #1 got:5Producer #1 put:6Consumer #1 got:6Producer #1 put:7Consumer #1 got:7Producer #1 put:8Consumer #1 got:8Producer #1 put:9Consumer #1 got:9


Recommended