• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAVA is a SHY animal, no need for synchronization

 
tom Su
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess what.. when I go one step further to name each thread, no more need for synchronizaion..
Multi-threading are kicking good without any more over-run..
package synchron;
public class synThread1 {
public static void main(String args[]) {
(new Thread(new Xyz(" a"))).start();
(new Thread(new Xyz(" b"))).start();
(new Thread(new Xyz(" c"))).start();
(new Thread(new Xyz(" d"))).start();
(new Thread(new Xyz(" e"))).start();
(new Thread(new Xyz(" f"))).start();
(new Thread(new Xyz(" g"))).start();
(new Thread(new Xyz(" h"))).start();
System.out.println("after all threads start ");
}// main
}
class Xyz implements Runnable {
int i = 5;
String sa = "";
Xyz(String sb) {
sa = sb ; }
public void run() {
i = 35;
while (true) {
for(long j=0;j< (long)(Math.random()*1.e9); j++) { double dd =Math.log(2.5);}<br /> System.out.print(sa+" i = " + i++ + " " );<br /> if ( i == 50 ) {<br /> System.out.println(sa +" stop at lower bound i = " + i);<br /> break;<br /> }<br /> if ( i > 100 ) {
System.out.println( sa +" stop at higher bound i = " + i);
break;
}
}// while
}
}// run
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go ahead to try your new found conclusion on your bank account! If you dare to do so
Sorry! I'm afraid that you got a wrong conclusion!
Roseanne
[This message has been edited by Roseanne Zhang (edited May 13, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!