Java中使用信号量——Semaphore
主线程中:
InitThread initThread=new InitThread(new Semaphore(0));//初始化一个子线程,传一个初值为0的信号量给它
Display.getDefault().asyncExec(initThread);
try {//此处会挂起,直到子线程完成工作,修改了信号量的值,主线程才会继续
initThread.getSemaphore().acquire();
} catch (InterruptedException e1) {
insertConsoleText("数据获取失败……\n");
}
子线程
class InitThread implements Runnable{
private Semaphore semaphore;
public InitThread(Semaphore semaphore){
this.semaphore=semaphore;
}
public Semaphore getSemaphore() {
return semaphore;
}
@SuppressWarnings("unchecked")
public void run() {
dataDos= (List<DataObject>)gui.getDataTableViewer().getInput();
anaDos=(List<DataObject>)gui.getMetaTableViews().get(viewerName).getInput();
excelCode=gui.getExcelCode().getText();
semaphore.release();
}
}
相关文档:
先来了解一下链表模式的原理:
首先写一个JavaBean,内容是要添加的元素和该元素的节点。
public class NodeBean implements Serializable
{
private Object data; //元素本身
private NodeBean next; //下一个节点
&n ......
1.计算某一月份的最大天数
Calendar time=Calendar.getInstance();
time.clear();
time.set(Calendar.YEAR,year); //year 为 int
time.set(Calendar.MONTH,i-1);//注意,Calendar对象默认一月为0
int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天数
注:在使用set方法之前,必须先 ......
Java的注销语句前要使用注释符“//”。
类声明关键字class创建了一个自定义类;类的名字为Welcome2,为Java声明类语句:class Welcome2 {}。
方法关键字main声明了main()方法,例:Public static void main(String args[]) { ......
public class Test4 {
public int binarySearch(int[] items, int value){
int startIndex = 0;
int stopIndex = items.length - 1;
int middle = (int)Math.flo ......