本文整理了Java中org.jgroups.util.Util.sleep()
方法的一些代码示例,展示了Util.sleep()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.sleep()
方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:sleep
[英]Sleep for timeout msecs. Returns when timeout has elapsed or thread was interrupted
[中]
代码示例来源:origin: wildfly/wildfly
/** Sleeps between floor and ceiling milliseconds, chosen randomly */
public static void sleepRandom(long floor,long ceiling) {
if(ceiling - floor <= 0) {
return;
}
long diff=ceiling - floor;
long r=(int)((Math.random() * 100000) % diff) + floor;
sleep(r);
}
代码示例来源:origin: wildfly/wildfly
public void print(int i) throws Exception {
System.out.println("<-- " + i + " [sleeping for " + timeout + " msecs");
Util.sleep(timeout);
}
代码示例来源:origin: wildfly/wildfly
public void run() {
synchronized(status) {
status.setText(msg);
Util.sleep(2000);
status.setText("");
}
}
}.start();
代码示例来源:origin: wildfly/wildfly
private void sleep(final int variable_milliseconds_delay, final int nano_delay) {
final int millis = computeDelay(variable_milliseconds_delay);
if (millis != 0 || nano_delay != 0) {
Util.sleep(millis, nano_delay);
}
}
代码示例来源:origin: wildfly/wildfly
public static void waitUntil(long timeout, long interval, Condition condition) throws TimeoutException {
long target_time=System.currentTimeMillis() + timeout;
while(System.currentTimeMillis() <= target_time) {
if(condition.isMet())
return;
Util.sleep(interval);
}
throw new TimeoutException("Timeout " + timeout + " kicked in");
}
代码示例来源:origin: wildfly/wildfly
/**
* Waits until a list has the expected number of elements. Throws an exception if not met
* @param list The list
* @param expected_size The expected size
* @param timeout The time to wait (in ms)
* @param interval The interval at which to get the size of the list (in ms)
* @param <T> The type of the list
*/
public static <T> void waitUntilListHasSize(List<T> list,int expected_size,long timeout,long interval) {
if(list == null)
throw new IllegalStateException("list is null");
long target_time=System.currentTimeMillis() + timeout;
while(System.currentTimeMillis() < target_time) {
if(list.size() == expected_size)
break;
Util.sleep(interval);
}
assert list.size() == expected_size : "list doesn't have the expected (" + expected_size + ") elements: " + list;
}
代码示例来源:origin: wildfly/wildfly
public void setState(InputStream istream) throws Exception {
total_received=0;
int received=0;
while(true) {
byte[] buf=new byte[10000];
received=istream.read(buf);
if(received < 0)
break;
if(delay > 0)
Util.sleep(delay);
total_received+=received;
if(requester_fails)
throw new Exception("booom - requester failed");
}
stop=System.currentTimeMillis();
System.out.println("<-- received " + Util.printBytes(total_received) + " in " + (stop-start) + "ms");
}
代码示例来源:origin: wildfly/wildfly
public void run() {
while(!Thread.currentThread().isInterrupted()) {
synchronized(BaseServer.this) {
for(Iterator<Entry<Address,Connection>> it=conns.entrySet().iterator();it.hasNext();) {
Entry<Address,Connection> entry=it.next();
Connection c=entry.getValue();
if(c.isExpired(System.nanoTime())) {
Util.close(c);
it.remove();
}
}
}
Util.sleep(reaperInterval);
}
}
}
代码示例来源:origin: wildfly/wildfly
public void getState(OutputStream ostream) throws Exception {
int frag_size=size / 10;
long bytes=0;
for(int i=0; i < 10; i++) {
byte[] buf=new byte[frag_size];
ostream.write(buf);
bytes+=buf.length;
if(provider_fails)
throw new Exception("booom - provider failed");
if(delay > 0)
Util.sleep(delay);
}
int remaining=size - (10 * frag_size);
if(remaining > 0) {
byte[] buf=new byte[remaining];
ostream.write(buf);
bytes+=buf.length;
}
System.out.println("--> wrote " + Util.printBytes(bytes));
}
代码示例来源:origin: wildfly/wildfly
public static void main(String args[]) {
try {
QuoteServer server=new QuoteServer();
server.start();
while(true) {
Util.sleep(10000);
}
}
catch(Throwable t) {
t.printStackTrace();
}
}
代码示例来源:origin: wildfly/wildfly
protected static Collection<InetAddress> getPhysicalAddresses(InetAddress addr, InetAddress bind_addr,
int port, final long timeout) throws Exception {
final DatagramSocket sock=new DatagramSocket(new InetSocketAddress(bind_addr, 0));
byte[] payload="member-addrs".getBytes();
DatagramPacket probe=new DatagramPacket(payload, 0, payload.length, addr, port);
sock.send(probe);
new Thread(() -> {
Util.sleep(timeout);
sock.close();
}).start();
long end_time=System.currentTimeMillis() + timeout;
while(System.currentTimeMillis() < end_time) {
byte[] buf=new byte[70000];
DatagramPacket rsp=new DatagramPacket(buf, 0, buf.length);
try {
sock.receive(rsp);
}
catch(Throwable t) {
break;
}
byte[] data=rsp.getData();
String response=new String(data, 0, rsp.getLength());
Collection<InetAddress> retval=parseAddresses(response);
if(retval != null && !retval.isEmpty())
return retval;
}
return null;
}
代码示例来源:origin: wildfly/wildfly
public void start(String props) throws Exception {
channel=new JChannel(props);
channel.setReceiver(this);
channel.connect("ViewDemo");
while(true) {
Util.sleep(10000);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void run() {
int cnt=1;
while(true) {
Util.sleep(1000);
MyNotification notif=new MyNotification("home.grown", this, cnt, "hello-" + cnt);
notif.setName("Bela Ban");
cnt++;
sendNotification(notif);
}
}
}.start();
代码示例来源:origin: wildfly/wildfly
public void run() {
for(int i=1; i <= number_of_msgs; i++) {
try {
Message msg=new Message(destination, buf);
if(oob)
msg.setFlag(Message.Flag.OOB);
if(dont_bundle)
msg.setFlag(Message.Flag.DONT_BUNDLE);
if(i > 0 && print > 0 && i % print == 0)
System.out.println("-- sent " + i);
channel.send(msg);
if(sleep_time > 0)
Util.sleep(sleep_time);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: wildfly/wildfly
public static void main(String[] args) {
JmxDemo demo=new JmxDemo();
demo.addNotificationListener((notification, handback) -> System.out.println(">> " + notification + ", handback=" + handback), null, "myHandback");
demo.startNotifications();
MBeanServer server=Util.getMBeanServer();
if(server != null) {
try {
JmxConfigurator.register(demo, server, "demo:name=DemoObject");
while(true) {
Util.sleep(10000);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: wildfly/wildfly
Util.sleep(50);
代码示例来源:origin: wildfly/wildfly
public void run() {
this.setName("SenderThread");
byte[] buf;
int cnt=0;
while(running) {
try {
req=createRandomRequest();
buf=req.toBuffer();
channel.send(new Message(null, buf));
System.out.print("-- num requests sent: " + cnt + "\r");
if(timeout > 0)
Util.sleep(timeout);
cnt++;
if(num > 0 && cnt > num) {
running=false;
cnt=0;
}
}
catch(Exception e) {
error(e.toString());
return;
}
}
}
}
代码示例来源:origin: wildfly/wildfly
System.out.println("Waiting for other members to join and fetch large state");
for(;;) {
Util.sleep(10000);
代码示例来源:origin: wildfly/wildfly
public void start() throws Exception {
channel=new JChannel(props);
disp=new MessageDispatcher(channel, this).setMembershipListener(this);
channel.connect("MessageDispatcherSpeedTestGroup");
try {
if(server) {
System.out.println("-- Started as server. Press ctrl-c to kill");
while(true) {
Util.sleep(10000);
}
}
else {
sendMessages(num);
}
}
catch(Throwable t) {
t.printStackTrace(System.err);
}
finally {
channel.close();
disp.stop();
}
}
代码示例来源:origin: wildfly/wildfly
public void run() {
Message msg=null, copy;
while(true) {
synchronized(this) {
try {
msg=send_queue.poll(1000, TimeUnit.MILLISECONDS);
if(msg == null) {
Util.sleep(1000);
continue;
}
}
catch(InterruptedException e) {
return;
}
copy=msg.copy().putHeader(id, new ABPHeader(Type.data, bit));
}
log.trace("%s: --> %s.msg(%d). Msg: %s", local_addr, copy.dest(), bit, copy.printHeaders());
down_prot.down(copy);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!