. Evaluasi Algoritma

Bagaimana kita memilih sebuah algoritma penjadualan CPU untuk sistem-sistem tertentu. Yang menjadipokok masalah adalah kriteria seperti apa yang digunakan untuk memilih sebuah algoritma. Untuk memilih suatu algoritma, pertama yang harus kita lakukan adalah menentukan ukuran dari suatu kriteria berdasarkan:
·          Memaksimalkan penggunaan CPU dibawah maksimum waktu responnya yaitu 1 detik.
·         Memaksimalkan throughput karena waktu turnaroundnya bergerak secara linier pada saat eksekusi proses.

Sinkronisasi dalam Java

Setiap objek dalam java mempunyai kunci yang unik yang tidak digunakan biasanya. Saat method dinyatakan sinkron, maka method dipanggil untuk mendapatkan kunci untuk objek tersebut. Saat kunci tersebut dipunyai thread yang lain maka thread tersebut diblok dan dimasukkan kedalam kumpulan kunci objek, misalnya:

public synchronized void enter(Object item) {
       while (count == BUFFER_SIZE)
            ;
       Thread.yeild();
                     ++count;
       buffer[in] = item;
       in = (in+1) % BUFFER_SIZE;
}

public synchronized void remove (){
Object item;
while (count == 0)
   ;
Thread.yeild();
--count;
item = buffer[out]
out = (out+1) % BUFFER_SIZE;
return item
}

Sinkronisasi.


Metoda Wait() dan Notify()

Thread akan memanggil method wait() saat:
  1. Thread melepaskan kunci untuk objek.
  2. Status thread diblok.
  3. Thread yang berada dalam status wait menunggu objek.

Thread akan memanggil method notify() saat: Thread yang dipilih diambil dari thread yang ada pada himpunan wait. Dengan cara:
  1. Pindahkan thread yang dipilih dari wait set ke entry set.
  2. Atur status dari thread yang dipilih dari blocked menjadi runnable.

Contoh Metoda Wait() dan Notify()

public synchronized void enter(Object item){
    while (count == BUFFER_SIZE) {
try{
    wait();
               } catch (InterruptedException e) {}
       }

      // add an item to the buffer
      ++count;
      buffer[in] = item;
     in = (in+1) % BUFFER_SIZE;
     notify();
}

public synchronized void remove(Object item){
       while (count == 0) {
try {
                  wait();
}
              catch (InterruptedException e) {}
        }  

       // remove an item to the buffer
       --count;
       item = buffer[out];
       out = (out+1) % BUFFER_SIZE;
       notify();
       return item;
}

Contoh Wait() dan Notify().


> <� h a s �ũ @ � l style='margin-left:36.0pt;text-align:justify;mso-layout-grid-align: none;text-autospace:none'>               }
       }

      private CircularList queue;
      private int timeSlice;
      private static final int DEFAULT_TIME_SLICE = 1000;
}

public class TesScheduler{
     public static void main()String args[]) {
Thread.currentThread().setpriority(Thread.Max_Priority);
Schedular CPUSchedular = new Scheduler ();
CPUSchedular.start()
TestThread t1 = new TestThread("Thread 1");
t1.start()
CpuSchedular.addThread(t1);
TestThread t2 = new TestThread("Thread 2");
t2.start()
CpuSchedular.addThread(t2);
TestThread t3 = new TestThread("Thread 1");
t3.start()
CpuSchedular.addThread(t3);
     }
}

Round Robin.

0 Response to ". Evaluasi Algoritma"

Posting Komentar

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme