-
public class DataNode extends Configured implements InterDatanodeProtocol,
-
ClientDatanodeProtocol, FSConstants, Runnable {
-
-
public static DataNode createDataNode(String args[], Configuration conf)
-
throws IOException {
-
DataNode dn = instantiateDataNode(args, conf);
-
runDatanodeDaemon(dn);
-
return dn;
-
}
-
-
public static void runDatanodeDaemon(DataNode dn) throws IOException {
-
dn.dataNodeThread = new Thread(dn, dnThreadName);
-
dn.dataNodeThread.setDaemon(true);
-
dn.dataNodeThread.start();
-
}
-
}
-
-
public static DataNode instantiateDataNode(String args[], Configuration conf)
-
throws IOException {
-
return makeInstance(dataDirs, conf);
-
}
-
-
public static DataNode makeInstance(String[] dataDirs, Configuration conf) {
-
return new DataNode(conf, dirs);
-
}
-
-
DataNode(Configuration conf, AbstractList<File> dataDirs)
-
throws IOException {
-
startDataNode(conf, dataDirs);
-
}
-
vid join(){
-
dataNodeThread.join();
-
}
-
-
void startDataNode(Configuration conf, AbstractList<File> dataDirs)
-
throws IOException {
-
}
-
-
public static void main(String args[]) {
-
DataNode datanode = createDataNode(args, null);
-
datanode.join();
-
}
-
}
-
import java.io.IOException;
-
-
public class ThreadTest extends Thread {
-
-
public class FirstThread extends Thread{
-
-
@Override
-
public void run(){
-
-
}
-
}
-
-
public class SecondThread implements Runnable{
-
-
@Override
-
public void run() {
-
-
}
-
}
-
-
public void run(){
-
for(int i = 1; i <= 50; i++){
-
try{
-
Thread.sleep(100);
-
} catch (InterruptedException ex){
-
ex.printStackTrace();
-
}
-
System.out.println(i);
-
}
-
}
-
-
public static void main(String[] args) throws IOException {
-
ThreadTest test = new ThreadTest();
-
Thread thd = new Thread(test);
-
-
// create and start 2mehtod
-
//1: FirstThread thd = new FirstThread();
-
// thd.Start();
-
-
//2: SecondThread thdx = new SecondThread()
-
//Thread thd = new Thread(thd);
-
//thd.Start();
-
-
// 如果不设置daemon,那么线程将输出50后才结束
-
thd.setDaemon(true);
-
thd.start();
-
System.out.println("isDaemon = " + thd.isDaemon());
-
System.in.read(); // 接受输入程序在此停顿,一旦有输入,main线程结束,守护线程自动结束
-
//thd.join();
-
}
-
}