List of usage examples for java.lang Runnable Runnable
Runnable
From source file:MainClass.java
public static void main(String args[]) { map = new WeakHashMap(); map.put("A", "B"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("A")) { try { Thread.sleep(1000); System.gc();/* w ww . ja v a2s . c o m*/ } catch (InterruptedException ignored) { } System.out.println("Has A"); System.gc(); } } }; Thread t = new Thread(runner); t.start(); System.out.println("Main waiting"); try { t.join(); } catch (InterruptedException ignored) { } System.gc(); }
From source file:Weak.java
public static void main(String args[]) { final Map map = new WeakHashMap(); map.put(new String("Java2s"), "www.java2s.com"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("Java2s")) { try { Thread.sleep(500); } catch (InterruptedException ignored) { }/* www . j a v a2s.c o m*/ System.out.println("Waiting"); System.gc(); } } }; Thread t = new Thread(runner); t.start(); System.out.println("Main waiting"); try { t.join(); } catch (InterruptedException ignored) { } }
From source file:Main.java
public static void main(String args[]) { final Map<String, String> map = new WeakHashMap<String, String>(); map.put(new String("A"), "B"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("A")) { try { Thread.sleep(500); } catch (InterruptedException ignored) { }//from w w w. j a v a 2 s.c o m System.gc(); } } }; Thread t = new Thread(runner); t.start(); try { t.join(); } catch (InterruptedException ignored) { } }
From source file:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override// www . j a v a 2 s. co m public void run() { JFrame frame = new JFrame(); frame.add(new ImagePanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true); } }); }
From source file:Main.java
public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JScrollPane scrollpane = new JScrollPane(new ScrollPaneArtifacts()); scrollpane.getViewport().setPreferredSize(new Dimension(400, 400)); JFrame frame = new JFrame("ScrollPaneArtifacts"); frame.getContentPane().add(scrollpane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();//from w w w .ja va 2 s.com frame.setLocationRelativeTo(null); frame.setVisible(true); } }); }
From source file:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Date date = new Date(); final JLabel timeLabel = new JLabel(date.toString()); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { date.setTime(System.currentTimeMillis()); timeLabel.setText(date.toString()); }//w w w . j ava 2 s . c o m }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
From source file:TimerOneShot2000.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(200, 200);//ww w. j a va2 s . c om shell.open(); display.timerExec(2000, new Runnable() { public void run() { System.out.println("2000"); } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Test.java
public static void main(String[] args) { final Lock firstLock = new ReentrantLock(); final Lock secondLock = new ReentrantLock(); firstLock.lock();/*from www. j a v a 2s . c o m*/ Thread secondThread = new Thread(new Runnable() { public void run() { secondLock.lock(); firstLock.lock(); } }); secondThread.start(); try { Thread.sleep(250); } catch (InterruptedException e) { e.printStackTrace(); } secondLock.lock(); secondLock.unlock(); firstLock.unlock(); }
From source file:Main.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override//from w w w .ja va 2s .com public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new ImagePanel("yourImage.JPG")); frame.pack(); frame.setVisible(true); } }); }
From source file:Main.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override/*from www . j av a 2 s .co m*/ public void run() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new LoadImage()); f.pack(); f.setVisible(true); } }); }