List of usage examples for java.lang InterruptedException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { int maximum = 100; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Integer[] oneRow = { 0, 0, 0, 0 }; String[] headers = { "A", "B", "C", "D" }; Integer[][] data = { oneRow, oneRow, oneRow, oneRow, oneRow, }; DefaultTableModel model = new DefaultTableModel(data, headers); JTable table = new JTable(model); table.setDefaultRenderer(Object.class, new ProgressRenderer(0, maximum)); table.setPreferredScrollableViewportSize(table.getPreferredSize()); frame.add(new JScrollPane(table)); frame.pack();// ww w . j a v a 2s. c om frame.setVisible(true); new Thread(new Runnable() { @Override public void run() { Object waiter = new Object(); synchronized (waiter) { int rows = model.getRowCount(); int columns = model.getColumnCount(); Random random = new Random(System.currentTimeMillis()); boolean done = false; while (!done) { int row = random.nextInt(rows); int column = random.nextInt(columns); Integer value = (Integer) model.getValueAt(row, column); value++; if (value <= maximum) { model.setValueAt(value, row, column); try { waiter.wait(15); } catch (InterruptedException e) { e.printStackTrace(); } } done = true; for (row = 0; row < rows; row++) { for (column = 0; column < columns; column++) { if (!model.getValueAt(row, column).equals(maximum)) { done = false; break; } } if (!done) { break; } } } } } }).start(); }
From source file:Signaling.java
public static void main(String[] args) { try {//from w w w.j a v a 2 s . co m print("creating BooleanLock instance"); BooleanLock ready = new BooleanLock(false); print("creating Signaling instance"); new Signaling(ready); print("about to sleep for 3 seconds"); Thread.sleep(3000); print("about to setValue to true"); ready.setValue(true); print("ready.isTrue()=" + ready.isTrue()); } catch (InterruptedException x) { x.printStackTrace(); } }
From source file:fr.irit.smac.libs.tooling.examples.plot.local.LocalChart.java
public static void main(String[] args) { // First, we inform the server that the chart "Layer" must be of type // PLOT// ww w . j a va 2 s . co m AgentPlot.getServer().configChart("Layer", ChartType.PLOT); // Add plots to the chart "Layer" for serie #0 AgentPlot.getChart("Layer").add(1, 2); AgentPlot.getChart("Layer").add(2, 2.5); AgentPlot.getChart("Layer").add(2, 3); // Add plots to the chart "Layer" for serie "My serie" AgentPlot.getChart("Layer").add("My serie", 21, 2); AgentPlot.getChart("Layer").add("My serie", 12, 2.5); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Add plots to the chart "My Chart" which will be created during this // call AgentPlot.getChart("My chart").add(2, 3); AgentPlot.getChart("My chart").add(3, 3); AgentPlot.getChart("My chart").add(3, 4); // Access the JFreeChart object (only from the server side) JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart(); // Change its title chart.getTitle().setText("New title"); // Close chart // AgentPlot.getChart("My chart").close(); // AgentPlot.getChart("Layer").close(); }
From source file:fr.irit.smac.libs.tooling.plot.example.local.LocalChart.java
public static void main(String[] args) { // First, we inform the server that the chart "Layer" must be of type // PLOT/* w ww . j a v a 2 s. com*/ AgentPlot.getServer().configChart("Layer", EChartType.PLOT); // Add plots to the chart "Layer" for serie #0 AgentPlot.getChart("Layer").add(1, 2); AgentPlot.getChart("Layer").add(2, 2.5); AgentPlot.getChart("Layer").add(2, 3); // Add plots to the chart "Layer" for serie "My serie" AgentPlot.getChart("Layer").add("My serie", 21, 2); AgentPlot.getChart("Layer").add("My serie", 12, 2.5); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Add plots to the chart "My Chart" which will be created during this // call AgentPlot.getChart("My chart").add(2, 3); AgentPlot.getChart("My chart").add(3, 3); AgentPlot.getChart("My chart").add(3, 4); // Access the JFreeChart object (only from the server side) JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart(); // Change its title chart.getTitle().setText("New title"); // Close chart // AgentPlot.getChart("My chart").close(); // AgentPlot.getChart("Layer").close(); }
From source file:com.camel.crawler.WebCrawler.java
public static void main(String[] args) { WebCrawler crawler = new WebCrawler(); boolean finished = true; while (finished) { try {//from w ww . ja v a 2s .c om pageInit++; System.out.println("url num:=" + pageInit); try { crawler.fetchWeb(URL_PRE + String.valueOf(pageInit) + "/"); } catch (IOException e) { pageInit--; e.printStackTrace(); //?1? try { System.out.println("exception sleep 1 min"); Thread.sleep(60000); } catch (InterruptedException e1) { e1.printStackTrace(); } } //????crawler if (pageInit == pageEnd) { finished = false; } try { Thread.sleep(700); } catch (InterruptedException e) { e.printStackTrace(); } } catch (Exception e) { System.out.println("unknow exception"); e.printStackTrace(); } } }
From source file:com.intel.cosbench.driver.random.RangeIntGenerator.java
public static void main(String[] args) { final String pattern = "r(50,100)"; final int all = 5; int i = 0;/*from w w w. j a v a2 s. c o m*/ Vector<TestThread> threads = new Vector<TestThread>(); RangeIntGenerator gen = RangeIntGenerator.parse(pattern); for (i = 0; i < all; i++) { TestThread thread = new TestThread(gen, i + 1, all); threads.add(thread); thread.start(); } try { for (i = 0; i < all; i++) { threads.elementAt(i).join(); } } catch (InterruptedException ie) { ie.printStackTrace(); } }
From source file:InterruptibleSyncBlock.java
public static void main(String[] args) { try {/*from ww w .ja v a 2 s.c o m*/ InterruptibleSyncBlock sb = new InterruptibleSyncBlock(); Thread t1 = launch(sb, "T1"); Thread.sleep(500); Thread t2 = launch(sb, "T2"); Thread t3 = launch(sb, "T3"); Thread.sleep(1000); print("about to interrupt T2"); t2.interrupt(); print("just interrupted T2"); } catch (InterruptedException x) { x.printStackTrace(); } }
From source file:com.intel.cosbench.driver.generator.RangeIntGenerator.java
public static void main(String[] args) { final String pattern = "r(51,1000)"; final int all = 5; int i = 0;//from ww w. j a v a 2 s . co m Vector<TestThread> threads = new Vector<TestThread>(); RangeIntGenerator gen = RangeIntGenerator.parse(pattern); for (i = 0; i < all; i++) { TestThread thread = new TestThread(gen, i + 1, all); threads.add(thread); thread.start(); } try { for (i = 0; i < all; i++) { threads.elementAt(i).join(); } } catch (InterruptedException ie) { ie.printStackTrace(); } }
From source file:kafka.examples.producer.BasicProducerExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {//from w w w . java 2 s.c o m Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); Boolean syncSend = res.getBoolean("syncsend"); long noOfMessages = res.getLong("messages"); long delay = res.getLong("delay"); String messageType = res.getString("messagetype"); Properties producerConfig = new Properties(); producerConfig.put("bootstrap.servers", brokerList); producerConfig.put("client.id", "basic-producer"); producerConfig.put("acks", "all"); producerConfig.put("retries", "3"); producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { producer.send(topic, getKey(i), getEvent(messageType, i)); try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } producer.close(); } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }
From source file:TransitionDetectorMain.java
public static void main(String[] args) { try {/* w w w.j a v a 2 s. co m*/ TransitionDetector td = new TransitionDetector(false); Thread threadA = startTrueWaiter(td, "threadA"); Thread threadB = startFalseWaiter(td, "threadB"); Thread.sleep(200); print("td=" + td + ", about to set to 'false'"); td.setValue(false); Thread.sleep(200); print("td=" + td + ", about to set to 'true'"); td.setValue(true); Thread.sleep(200); print("td=" + td + ", about to pulse value"); td.pulseValue(); Thread.sleep(200); threadA.interrupt(); threadB.interrupt(); } catch (InterruptedException x) { x.printStackTrace(); } }