Hello Multithreaded World 2.0

Yes I’m proud to announce HelloMultithreadedWorld 2.0 ,

There have been serious changes to the codebase to make it better OO. which broke compatibilities to HelloMultithreadeWorld 1.0. So please Upgrade to the newest version .


public class HelloWorldStart {
HelloWorld hello = HelloWorld.getHello();

public static void main(String[] args){
HelloWorldStart starter = new HelloWorldStart();

private void run(){
for(int i=0; i <= hello.getStringLength() ;i++){ Runnable threadJod = new HelloWorldRunnable(i); Thread helloWorldThread = new Thread(threadJod); helloWorldThread.start(); } //for }//Run }//class [/sourcecode] [sourcecode language="java"] public class HelloWorldRunnable implements Runnable { int place; HelloWorld hello = HelloWorld.getHello(); public HelloWorldRunnable(int i){ place = i; } // constructor public void run(){ while (true){ if(hello.getCounter() == place ){ /* uncomment the following if you wanna see "more" */ /* try{ Thread.sleep(20); }catch (Exception ex){} */ if (place == hello.getStringLength()) { System.out.println(""); }//if else { System.out.print(hello.getLetter(place)); hello.incCounter(); }//else break; }//if }//while }//run }//class [/sourcecode] [sourcecode language="java"] public class HelloWorld { private static HelloWorld hello = new HelloWorld(); private int counter = 0; private String[] letters= {"H","e","l","l","o"," ","m","u","l","t","i","t","h","r","e","a","d","e","d"," ","w","o","r","l","d"}; private HelloWorld(){ } public static HelloWorld getHello(){ return hello; }//getHello public int getCounter(){ return counter; }// getcounter public void incCounter(){ counter++; } // incounter public String getLetter(int i){ return letters[i]; } //getletter public int getStringLength(){ return letters.length; }//getStringLenth } //class [/sourcecode]

Leave a Reply