List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:Main.java
public static void main(String[] args) throws Exception { Main q = new Main(); long start = System.currentTimeMillis(); // Run the queues for 30 seconds, add CPU-light and CPU-weight tasks // every second. while (System.currentTimeMillis() - start <= 30 * 1000L) { q.runOrQueueHeavyTask(new SampleHeavyTask()); q.runOrQueueLightTask(new SampleLightTask()); Thread.sleep(1000L); }/*w w w .j a v a2s. c om*/ q.shutDownNow(); }
From source file:com.offbynull.peernetic.debug.visualizer.App.java
public static void main(String[] args) throws Throwable { Random random = new Random(); Visualizer<Integer> visualizer = new JGraphXVisualizer<>(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Recorder<Integer> recorder = new XStreamRecorder(baos); visualizer.visualize(recorder, null); visualizer.step("Adding nodes 1 and 2", new AddNodeCommand<>(1), new ChangeNodeCommand(1, null, new Point(random.nextInt(400), random.nextInt(400)), Color.RED), new AddNodeCommand<>(2), new ChangeNodeCommand(2, null, new Point(random.nextInt(400), random.nextInt(400)), Color.BLUE)); Thread.sleep(500); visualizer.step("Adding nodes 3 and 4", new AddNodeCommand<>(3), new ChangeNodeCommand(3, null, new Point(random.nextInt(400), random.nextInt(400)), Color.ORANGE), new AddNodeCommand<>(4), new ChangeNodeCommand(4, null, new Point(random.nextInt(400), random.nextInt(400)), Color.PINK)); Thread.sleep(500);//w w w . ja v a 2 s . c om visualizer.step("Connecting 1/2/3 to 4", new AddEdgeCommand<>(1, 4), new AddEdgeCommand<>(2, 4), new AddEdgeCommand<>(3, 4)); Thread.sleep(500); visualizer.step("Adding trigger to 4 when no more edges", new TriggerOnLingeringNodeCommand(4, new RemoveNodeCommand<>(4))); Thread.sleep(500); visualizer.step("Removing connections from 1 and 2", new RemoveEdgeCommand<>(1, 4), new RemoveEdgeCommand<>(2, 4)); Thread.sleep(500); visualizer.step("Removing connections from 3", new RemoveEdgeCommand<>(3, 4)); Thread.sleep(500); recorder.close(); Thread.sleep(2000); JGraphXVisualizer<Integer> visualizer2 = new JGraphXVisualizer<>(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); Player<Integer> player = new XStreamPlayer<>(bais); visualizer2.visualize(); player.play(visualizer2); }
From source file:Main.java
public static void main(String[] args) throws Exception { new Thread(() -> { int submitCount = 0; while (submitCount < 10) { if (!updating) { futureList.add(pool.submit(callable)); submitCount++;/*w ww. ja v a 2 s . c o m*/ } try { Thread.sleep(1000); // arbitrary } catch (Exception e) { e.printStackTrace(); } } }).start(); // update thread new Thread(() -> { int updateCount = 0; while (updateCount < 5) { doUpdate(); updateCount++; try { Thread.sleep(2000); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
From source file:com.reversemind.hypergate.spring.HyperGateClientSpringContextLoader.java
public static void main(String... args) throws Exception { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/hypergate-client-context.xml"); HyperGateClientServerDiscovery client = (HyperGateClientServerDiscovery) applicationContext.getBean( AbstractContainerHyperGateClient.CLIENT_DISCOVERY_BUILDER_NAME, AbstractContainerHyperGateClient.CLASS_HYPERGATE_CLIENT_SERVER_DISCOVERY); client.start();//from www . jav a 2 s . co m Thread.sleep(40000); client.shutdown(); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//from www .j a va2 s.c om } SystemTray tray = SystemTray.getSystemTray(); PropertyChangeListener pcl; pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { System.out.println("Property changed = " + pce.getPropertyName()); TrayIcon[] tia = (TrayIcon[]) pce.getOldValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } tia = (TrayIcon[]) pce.getNewValue(); if (tia != null) { for (int i = 0; i < tia.length; i++) System.out.println(tia[i]); } } }; tray.addPropertyChangeListener("trayIcons", pcl); PropertyChangeListener[] listeners = tray.getPropertyChangeListeners("trayIcons"); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); TrayIcon icon = null; tray.add(icon = new TrayIcon(bi)); Thread.sleep(3000); tray.remove(icon); Thread.sleep(3000); System.exit(0); }
From source file:ThreadPoolMain.java
public static void main(String[] args) { try {//www . j a va 2 s . co m ThreadPool pool = new ThreadPool(3); Runnable ra = makeRunnable("RA", 3000); pool.execute(ra); Runnable rb = makeRunnable("RB", 1000); pool.execute(rb); Runnable rc = makeRunnable("RC", 2000); pool.execute(rc); Runnable rd = makeRunnable("RD", 60000); pool.execute(rd); Runnable re = makeRunnable("RE", 1000); pool.execute(re); pool.stopRequestIdleWorkers(); Thread.sleep(2000); pool.stopRequestIdleWorkers(); Thread.sleep(5000); pool.stopRequestAllWorkers(); } catch (InterruptedException ix) { ix.printStackTrace(); } }
From source file:org.springone2gx_2011.integration.aggregator.AggregatorDemo.java
/** * @param args/*from w w w . jav a2 s.c om*/ */ public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("aggregator-config.xml", AggregatorDemo.class); MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class); int iterations = 13; for (int i = 0; i < iterations; i++) { Message<?> message = MessageBuilder.withPayload(i).setCorrelationId(1).setSequenceNumber(i) .setSequenceSize(iterations).build(); System.out.println("Sending: " + message); inputChannel.send(message); Thread.sleep(1000); } }
From source file:edu.berkeley.path.next.trafficMonitor.trafficMonitorApp.java
public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jms-publish.xml"); context.start();//from www . ja v a 2 s . co m final Logger logger = LogManager.getLogger(trafficMonitorApp.class.getName()); logger.info("trafficMonitorApp initialized "); JmsPublish jmsPublish = context.getBean(JmsPublish.class); int x = 0; String msg = "status"; while (x < 7) { //use SLF interface which provides for parameterized logging logger.info("trafficMonitorApp sendTrafficUpdate {} ", x); jmsPublish.sendTrafficUpdate(msg); Thread.sleep(3000); x++; } }
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];//from w w w . j a va 2s. co m PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, DocFlavor.INPUT_STREAM.GIF, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.exit(0); } }; job.addPrintJobListener(listener); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } }
From source file:AlternateSuspendResume.java
public static void main(String[] args) { AlternateSuspendResume asr = new AlternateSuspendResume(); Thread t = new Thread(asr); t.start();/*w ww . j av a 2s. c o m*/ try { Thread.sleep(1000); } catch (InterruptedException x) { } for (int i = 0; i < 10; i++) { asr.suspendRequest(); try { Thread.sleep(350); } catch (InterruptedException x) { } System.out.println("dsr.areValuesEqual()=" + asr.areValuesEqual()); asr.resumeRequest(); try { Thread.sleep((long) (Math.random() * 2000.0)); } catch (InterruptedException x) { } } System.exit(0); }