⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverthread.java

📁 用NETBEANS做的一个关于Java的小小的demo.大家赐教
💻 JAVA
字号:
/*
 * ServerThread.java
 *
 * Created on 2007年9月13日, 下午10:30
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package OldThread;

/**
 *
 * @author Administrator
 */
public class ServerThread {
    
    Object concLock = new Object();
    
    int count = 2;
    
    public void runTwoThreads() {
        
        //启动两个线程去初始化组件
        
        new Thread(new ComponentThread1(this)).start();
        
        new Thread(new ComponentThread1(this)).start();
        
        // Wait for other thread
        
        while(count != 0) {
            
            System.out.println("count = " + count);
            
            synchronized(concLock) {
                
                try {
                    
                    concLock.wait();
                    
                    System.out.println("Wake up.");
                    
                } catch (InterruptedException ie) { //处理异常
                    
                }
                
            }
            
            System.out.println("Server is up.");
            
        }
    }
    
    public void callBack() {
        
        synchronized(concLock) {
            
            count--;
            
            concLock.notifyAll();
            
        }
        
    }
    
    public static void main(String[] args){
        
        ServerThread server = new ServerThread();
        
        server.runTwoThreads();
        
    }
    
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -