Showing posts with label thread. Show all posts
Showing posts with label thread. Show all posts

January 29, 2013

Thread Enumerator Example

Java example to set condition in Thread 


package yahoofinance;

public class ThreadExamples implements Runnable {
   
    public enum Traffic { NORTH, SOUTH, EAST, WEST, NOTHING }
    static Traffic isOn = Traffic.NOTHING;
    @Override
    public void run() {
        while(true){
            switch (isOn) {
            case NORTH:
                System.out.println(" north is on ");
                break;
            case SOUTH:
                System.out.println(" south is on ");
                break;
            case EAST:
                System.out.println(" east is on ");
                break;
            case WEST:
                System.out.println(" west is on ");
                break;
            case NOTHING:
                System.out.println(" default is on ");
                break;
            default:
                System.out.println(" default is on ");
                break;
            }
        }
       
    }
   
    public static void main(String[] election) throws InterruptedException {
         ThreadExamples t = new ThreadExamples();
         Thread th = new Thread(t);
         th.start();
         th.sleep(5000);
         isOn = Traffic.NORTH;
         th.sleep(1000);
         isOn = Traffic.WEST;
    }

}

How to manipulate/control a running thread from another class.



http://belazy.blog.com/

February 01, 2012

Network monitoring in java to get all computer names in the network


Java Network Monitoring : To get all intra networked computer list


//Java network program to list out all available computers in intranet

import java.io.*;

public class NetworkUsers
{
static String all;
public static void main(String[] args)
{try {
// Execute command

Process child = Runtime.getRuntime().exec("net view");
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1)
{
char e=(char)c;
System.out.println(e);
//process((char)c);
}
in.close();
} catch (IOException e) { } }

private static void process(char c) {
// TODO Auto-generated method stub
System.out.print(c);
//all =String.valueOf(c) +all;
// System.out.println(all);
}


}


 Please provide your valuable comments

Facebook comments