org.jgroups.util.Util.sleep()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.jgroups.util.Util.sleep()方法的一些代码示例,展示了Util.sleep()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.sleep()方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:sleep

Util.sleep介绍

[英]Sleep for timeout msecs. Returns when timeout has elapsed or thread was interrupted
[中]

代码示例

代码示例来源:origin: wildfly/wildfly

  1. /** Sleeps between floor and ceiling milliseconds, chosen randomly */
  2. public static void sleepRandom(long floor,long ceiling) {
  3. if(ceiling - floor <= 0) {
  4. return;
  5. }
  6. long diff=ceiling - floor;
  7. long r=(int)((Math.random() * 100000) % diff) + floor;
  8. sleep(r);
  9. }

代码示例来源:origin: wildfly/wildfly

  1. public void print(int i) throws Exception {
  2. System.out.println("<-- " + i + " [sleeping for " + timeout + " msecs");
  3. Util.sleep(timeout);
  4. }

代码示例来源:origin: wildfly/wildfly

  1. public void run() {
  2. synchronized(status) {
  3. status.setText(msg);
  4. Util.sleep(2000);
  5. status.setText("");
  6. }
  7. }
  8. }.start();

代码示例来源:origin: wildfly/wildfly

  1. private void sleep(final int variable_milliseconds_delay, final int nano_delay) {
  2. final int millis = computeDelay(variable_milliseconds_delay);
  3. if (millis != 0 || nano_delay != 0) {
  4. Util.sleep(millis, nano_delay);
  5. }
  6. }

代码示例来源:origin: wildfly/wildfly

  1. public static void waitUntil(long timeout, long interval, Condition condition) throws TimeoutException {
  2. long target_time=System.currentTimeMillis() + timeout;
  3. while(System.currentTimeMillis() <= target_time) {
  4. if(condition.isMet())
  5. return;
  6. Util.sleep(interval);
  7. }
  8. throw new TimeoutException("Timeout " + timeout + " kicked in");
  9. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Waits until a list has the expected number of elements. Throws an exception if not met
  3. * @param list The list
  4. * @param expected_size The expected size
  5. * @param timeout The time to wait (in ms)
  6. * @param interval The interval at which to get the size of the list (in ms)
  7. * @param <T> The type of the list
  8. */
  9. public static <T> void waitUntilListHasSize(List<T> list,int expected_size,long timeout,long interval) {
  10. if(list == null)
  11. throw new IllegalStateException("list is null");
  12. long target_time=System.currentTimeMillis() + timeout;
  13. while(System.currentTimeMillis() < target_time) {
  14. if(list.size() == expected_size)
  15. break;
  16. Util.sleep(interval);
  17. }
  18. assert list.size() == expected_size : "list doesn't have the expected (" + expected_size + ") elements: " + list;
  19. }

代码示例来源:origin: wildfly/wildfly

  1. public void setState(InputStream istream) throws Exception {
  2. total_received=0;
  3. int received=0;
  4. while(true) {
  5. byte[] buf=new byte[10000];
  6. received=istream.read(buf);
  7. if(received < 0)
  8. break;
  9. if(delay > 0)
  10. Util.sleep(delay);
  11. total_received+=received;
  12. if(requester_fails)
  13. throw new Exception("booom - requester failed");
  14. }
  15. stop=System.currentTimeMillis();
  16. System.out.println("<-- received " + Util.printBytes(total_received) + " in " + (stop-start) + "ms");
  17. }

代码示例来源:origin: wildfly/wildfly

  1. public void run() {
  2. while(!Thread.currentThread().isInterrupted()) {
  3. synchronized(BaseServer.this) {
  4. for(Iterator<Entry<Address,Connection>> it=conns.entrySet().iterator();it.hasNext();) {
  5. Entry<Address,Connection> entry=it.next();
  6. Connection c=entry.getValue();
  7. if(c.isExpired(System.nanoTime())) {
  8. Util.close(c);
  9. it.remove();
  10. }
  11. }
  12. }
  13. Util.sleep(reaperInterval);
  14. }
  15. }
  16. }

代码示例来源:origin: wildfly/wildfly

  1. public void getState(OutputStream ostream) throws Exception {
  2. int frag_size=size / 10;
  3. long bytes=0;
  4. for(int i=0; i < 10; i++) {
  5. byte[] buf=new byte[frag_size];
  6. ostream.write(buf);
  7. bytes+=buf.length;
  8. if(provider_fails)
  9. throw new Exception("booom - provider failed");
  10. if(delay > 0)
  11. Util.sleep(delay);
  12. }
  13. int remaining=size - (10 * frag_size);
  14. if(remaining > 0) {
  15. byte[] buf=new byte[remaining];
  16. ostream.write(buf);
  17. bytes+=buf.length;
  18. }
  19. System.out.println("--> wrote " + Util.printBytes(bytes));
  20. }

代码示例来源:origin: wildfly/wildfly

  1. public static void main(String args[]) {
  2. try {
  3. QuoteServer server=new QuoteServer();
  4. server.start();
  5. while(true) {
  6. Util.sleep(10000);
  7. }
  8. }
  9. catch(Throwable t) {
  10. t.printStackTrace();
  11. }
  12. }

代码示例来源:origin: wildfly/wildfly

  1. protected static Collection<InetAddress> getPhysicalAddresses(InetAddress addr, InetAddress bind_addr,
  2. int port, final long timeout) throws Exception {
  3. final DatagramSocket sock=new DatagramSocket(new InetSocketAddress(bind_addr, 0));
  4. byte[] payload="member-addrs".getBytes();
  5. DatagramPacket probe=new DatagramPacket(payload, 0, payload.length, addr, port);
  6. sock.send(probe);
  7. new Thread(() -> {
  8. Util.sleep(timeout);
  9. sock.close();
  10. }).start();
  11. long end_time=System.currentTimeMillis() + timeout;
  12. while(System.currentTimeMillis() < end_time) {
  13. byte[] buf=new byte[70000];
  14. DatagramPacket rsp=new DatagramPacket(buf, 0, buf.length);
  15. try {
  16. sock.receive(rsp);
  17. }
  18. catch(Throwable t) {
  19. break;
  20. }
  21. byte[] data=rsp.getData();
  22. String response=new String(data, 0, rsp.getLength());
  23. Collection<InetAddress> retval=parseAddresses(response);
  24. if(retval != null && !retval.isEmpty())
  25. return retval;
  26. }
  27. return null;
  28. }

代码示例来源:origin: wildfly/wildfly

  1. public void start(String props) throws Exception {
  2. channel=new JChannel(props);
  3. channel.setReceiver(this);
  4. channel.connect("ViewDemo");
  5. while(true) {
  6. Util.sleep(10000);
  7. }
  8. }

代码示例来源:origin: wildfly/wildfly

  1. @Override
  2. public void run() {
  3. int cnt=1;
  4. while(true) {
  5. Util.sleep(1000);
  6. MyNotification notif=new MyNotification("home.grown", this, cnt, "hello-" + cnt);
  7. notif.setName("Bela Ban");
  8. cnt++;
  9. sendNotification(notif);
  10. }
  11. }
  12. }.start();

代码示例来源:origin: wildfly/wildfly

  1. public void run() {
  2. for(int i=1; i <= number_of_msgs; i++) {
  3. try {
  4. Message msg=new Message(destination, buf);
  5. if(oob)
  6. msg.setFlag(Message.Flag.OOB);
  7. if(dont_bundle)
  8. msg.setFlag(Message.Flag.DONT_BUNDLE);
  9. if(i > 0 && print > 0 && i % print == 0)
  10. System.out.println("-- sent " + i);
  11. channel.send(msg);
  12. if(sleep_time > 0)
  13. Util.sleep(sleep_time);
  14. }
  15. catch(Exception e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }
  20. }

代码示例来源:origin: wildfly/wildfly

  1. public static void main(String[] args) {
  2. JmxDemo demo=new JmxDemo();
  3. demo.addNotificationListener((notification, handback) -> System.out.println(">> " + notification + ", handback=" + handback), null, "myHandback");
  4. demo.startNotifications();
  5. MBeanServer server=Util.getMBeanServer();
  6. if(server != null) {
  7. try {
  8. JmxConfigurator.register(demo, server, "demo:name=DemoObject");
  9. while(true) {
  10. Util.sleep(10000);
  11. }
  12. }
  13. catch(Exception e) {
  14. e.printStackTrace();
  15. }
  16. }
  17. }

代码示例来源:origin: wildfly/wildfly

  1. Util.sleep(50);

代码示例来源:origin: wildfly/wildfly

  1. public void run() {
  2. this.setName("SenderThread");
  3. byte[] buf;
  4. int cnt=0;
  5. while(running) {
  6. try {
  7. req=createRandomRequest();
  8. buf=req.toBuffer();
  9. channel.send(new Message(null, buf));
  10. System.out.print("-- num requests sent: " + cnt + "\r");
  11. if(timeout > 0)
  12. Util.sleep(timeout);
  13. cnt++;
  14. if(num > 0 && cnt > num) {
  15. running=false;
  16. cnt=0;
  17. }
  18. }
  19. catch(Exception e) {
  20. error(e.toString());
  21. return;
  22. }
  23. }
  24. }
  25. }

代码示例来源:origin: wildfly/wildfly

  1. System.out.println("Waiting for other members to join and fetch large state");
  2. for(;;) {
  3. Util.sleep(10000);

代码示例来源:origin: wildfly/wildfly

  1. public void start() throws Exception {
  2. channel=new JChannel(props);
  3. disp=new MessageDispatcher(channel, this).setMembershipListener(this);
  4. channel.connect("MessageDispatcherSpeedTestGroup");
  5. try {
  6. if(server) {
  7. System.out.println("-- Started as server. Press ctrl-c to kill");
  8. while(true) {
  9. Util.sleep(10000);
  10. }
  11. }
  12. else {
  13. sendMessages(num);
  14. }
  15. }
  16. catch(Throwable t) {
  17. t.printStackTrace(System.err);
  18. }
  19. finally {
  20. channel.close();
  21. disp.stop();
  22. }
  23. }

代码示例来源:origin: wildfly/wildfly

  1. public void run() {
  2. Message msg=null, copy;
  3. while(true) {
  4. synchronized(this) {
  5. try {
  6. msg=send_queue.poll(1000, TimeUnit.MILLISECONDS);
  7. if(msg == null) {
  8. Util.sleep(1000);
  9. continue;
  10. }
  11. }
  12. catch(InterruptedException e) {
  13. return;
  14. }
  15. copy=msg.copy().putHeader(id, new ABPHeader(Type.data, bit));
  16. }
  17. log.trace("%s: --> %s.msg(%d). Msg: %s", local_addr, copy.dest(), bit, copy.printHeaders());
  18. down_prot.down(copy);
  19. }
  20. }
  21. }

相关文章

Util类方法