joineddownloadmessagebuffer.java
来自「一个基于NetBeans平台开发的」· Java 代码 · 共 41 行
JAVA
41 行
package com.sinpool.rivercrescent.BufferZone;
import java.util.Vector;
import com.sinpool.rivercrescent.interfaces.JoinedMessageBufferInterface;
import com.sinpool.rivercrescent.myutil.WakeUpAdapter;
public class JoinedDownloadMessageBuffer implements JoinedMessageBufferInterface{
private Vector MessageList = new Vector(5,5);
private boolean flag = false;
Thread wakeUp = null;
public synchronized void addElement(Object o){
MessageList.addElement(o);
try{
if ( wakeUp.isAlive() ) {
wakeUp.stop();
System.out.println("唤醒器被关闭。");
}
} catch (Exception e)
{System.out.println("中断wakeUp时出错,是一个可忽略的错误。");}
try{if (flag) {System.out.println("join 被唤醒");this.notify();flag = false;} }catch (Exception e) {}
}
public synchronized Object getMessage(int i){
if (MessageList.size() == 0) flag = true;
try{if (flag) {
wakeUp = new Thread( new WakeUpAdapter(this) );
wakeUp.start();
this.wait();
if ( MessageList.size() == 0 ) { System.out.println("join 被唤醒器叫醒!");flag = false; return null;}
}
}catch (Exception e) {}
return MessageList.get(i);
}
public synchronized int size(){
return MessageList.size();
}
public synchronized void remove(Object o){
MessageList.remove(o);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?