docallstuff.java

来自「用NETBEANS做的一个关于Java的小小的demo.大家赐教」· Java 代码 · 共 66 行

JAVA
66
字号
/*
 * DoCallStaff.java
 *
 * Created on 2007年9月14日, 上午12:21
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package newThread;

import java.util.concurrent.Callable;

/**
 *
 * @author Administrator
 */
public class DoCallStuff implements Callable<String>{ // *1
    
    private int aInt;
    
    public DoCallStuff(int aInt) {
        
        this.aInt = aInt;
        
    }
    
    public String call() throws Exception { //*2
        
        boolean resultOk = false;
        
        if(aInt == 0){
            
            resultOk = true;
            
        }  else if(aInt == 1){
            
            while(true){ //infinite loop
                
                System.out.println("looping....");
                
                Thread.sleep(3000);
                
            }
            
        } else {
            
            throw new Exception("Callable terminated with Exception!"); //*3
            
        }
        
        if(resultOk){
            
            return "Task done.";
            
        } else {
            
            return "Task failed";
            
        }
        
    }
    
}

⌨️ 快捷键说明

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