/*
* file PlatformCheck.java
*/
/**
* @author zahid Amin-ur-Rahman
* @version 1.0
* Copyright (C)
*/
package Platform;
/** Description -
* Program to check which type of JVM has been downloaded
* by looking at the scheduling scheme using Threads.
* If you see both Foo and Bar alternating then your JVM is using the time -
slicing
* scheduling scheme which means that you have download the JVM for windows
* if you only see Foo then your JVM is using the Round Robin scheduling
scheme
* The results described are according to a book.
* Also according to the book there is a debate whether programmers can use
* Threads effectively.
* perhaps this is the reason that in the book the while loop is endless
rather
* than the count being high enough to check for the results effectively and
analyse
* the scheduling pattern in order to use it constructively.
* Nonetheless I still think this is the best Java Book I have come across.
* The scheduling algorithm still needs polishing when using time - slicing
* Java Bundle version 1.3.0_02
* Can you sort the Time - slicing Algorithm please.
*/
public class PlatformCheck extends Object {
public static void main ( String args[]) {
Thread Foo = new TestThread("Foo");
Thread Bar = new TestThread("Bar");
// make certain priority levels are equal for both threads
Foo.setPriority(Thread.NORM_PRIORITY);
Bar.setPriority(Thread.NORM_PRIORITY);
// the start will call Testthread.run
Foo.start();
Bar.start();
} // end main
} // end PlatformCheck
class TestThread extends Thread {
// counts need to be high enough to see the scheduling pattern
// both threads will the call the run method MAXCOUNT times in total
private final int MAXCOUNT = 30;
private String message;
private int loopCounter = 0;
TestThread (String message) {
this.message = message;
}
// synchronise just for the hell of it even though incrementing int
primitive type
synchronized private int getLoopCounter(){
return this.loopCounter;
}
synchronized private int setLoopCounter(int ChangeValue){
return this.loopCounter += ChangeValue;
}
// the run method is overidden
public void run(){
while(true){
if (getLoopCounter() == MAXCOUNT)
break; // get out of the while loop
setLoopCounter(1);
System.out.println(message);
} // end while
return; // get out of the run method
}// end run
} // end of TestThread
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html