List of usage examples for java.lang Object Object
@HotSpotIntrinsicCandidate
public Object()
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }/*from ww w . j a va 2 s . co m*/ }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = null; System.out.println("Testing WeakReference."); reference = new WeakReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }
From source file:ThreadState.java
public static void main(String[] args) throws InterruptedException { Object syncObject = new Object(); ThreadState ts = new ThreadState(syncObject); System.out.println("Before start()-ts.isAlive():" + ts.isAlive()); System.out.println("#1:" + ts.getState()); ts.start();// w w w.j a v a2 s .co m System.out.println("After start()-ts.isAlive():" + ts.isAlive()); System.out.println("#2:" + ts.getState()); ts.setWait(true); Thread.currentThread().sleep(100); synchronized (syncObject) { System.out.println("#3:" + ts.getState()); ts.setWait(false); syncObject.notifyAll(); } Thread.currentThread().sleep(2000); System.out.println("#4:" + ts.getState()); ts.setKeepRunning(false); Thread.currentThread().sleep(2000); System.out.println("#5:" + ts.getState()); System.out.println("At the end. ts.isAlive():" + ts.isAlive()); }
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 va2s. com*/ 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:EmbeddedBroker.java
public static void main(String[] args) throws Exception { BrokerService broker = new BrokerService(); broker.setUseJmx(true);/*from w ww .java2 s .co m*/ broker.addConnector("tcp://localhost:61616"); broker.start(); // now lets wait forever to avoid the JVM terminating immediately Object lock = new Object(); synchronized (lock) { lock.wait(); } }
From source file:com.anton.dev.tqrbs2.basic.BasicJava.java
public static void main(String[] args) throws Exception { ConnectionFactory cf = new CachingConnectionFactory(); // set up the queue, exchange, binding on the broker RabbitAdmin admin = new RabbitAdmin(cf); Queue queue = new Queue("myQueue"); admin.declareQueue(queue);// w ww. jav a 2s . c om TopicExchange exchange = new TopicExchange("myExchange2"); admin.declareExchange(exchange); admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*")); // set up the listener and container SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf); Object listener = new Object() { public void handleMessage(String foo) { LOGGER.info("Recibiendo Java: " + foo); } }; MessageListenerAdapter adapter = new MessageListenerAdapter(listener); container.setMessageListener(adapter); container.setQueueNames("myQueue"); container.start(); // send something RabbitTemplate template = new RabbitTemplate(cf); String msg = "Hello, world Rabbit!"; LOGGER.info("Enviando Java: " + msg); template.convertAndSend("myExchange2", "foo.bar", msg); Thread.sleep(1000); container.stop(); }
From source file:ThreadViewer.java
public static void main(String[] args) { JFrame f = new JFrame(); ThreadViewer viewer = new ThreadViewer(); f.setContentPane(viewer);//from w ww . ja v a 2 s .c om f.setSize(500, 300); f.setVisible(true); f.setDefaultCloseOperation(1); // Keep the main thread from exiting by blocking // on wait() for a notification that never comes. Object lock = new Object(); synchronized (lock) { try { lock.wait(); } catch (InterruptedException x) { } } }
From source file:PrintfStuff.java
public static void main(String[] args) throws IOException { char three[] = { 't', 'h', 'r', 'e', 'e' }; System.out.printf("%b %n %c %n %s %n %s %n %d %n" + "%d %n %g %n %g %n %s %n", !false, '3', new String(three), "Three", 3, Long.MAX_VALUE, Math.PI, Double.MAX_VALUE, new Object()); }
From source file:blue.utility.ValuesUtility.java
public static void main(String args[]) { Object obj = new Object() { String val1 = "test"; String val2 = "test2"; String val3 = null; };//from ww w. ja v a2 s . c o m System.out.println(ToStringBuilder.reflectionToString(obj)); ValuesUtility.checkNullString(obj, true); System.out.println(ToStringBuilder.reflectionToString(obj)); }
From source file:uk.co.jemos.experiments.integration.HelloWorldApp.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("podamInputChannel", MessageChannel.class); Message<Object> intMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", int.class.toString()).build(); Message<Object> boolMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", boolean.class.toString()).build(); Message<Object> stringMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", String.class.getName()).build(); MessagingTemplate template = new MessagingTemplate(); Message reply = template.sendAndReceive(inputChannel, intMessage); logger.info(reply.getPayload());//from w w w . j a v a2 s .c om reply = template.sendAndReceive(inputChannel, boolMessage); logger.info(reply.getPayload()); reply = template.sendAndReceive(inputChannel, stringMessage); logger.info(reply.getPayload()); context.close(); }
From source file:org.apache.jmeter.protocol.http.proxy.NonGuiProxySample.java
public static void main(String[] args) throws IllegalUserActionException, IOException { JMeterUtils.setJMeterHome("./"); // Or wherever you put it. JMeterUtils.loadJMeterProperties(JMeterUtils.getJMeterBinDir() + "/jmeter.properties"); JMeterUtils.initLocale();//www . ja v a 2 s . co m TestPlan testPlan = new TestPlan(); ThreadGroup threadGroup = new ThreadGroup(); ListedHashTree testPlanTree = new ListedHashTree(); testPlanTree.add(testPlan); testPlanTree.add(threadGroup, testPlan); JMeterTreeModel treeModel = new JMeterTreeModel(new Object()); JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot(); treeModel.addSubTree(testPlanTree, root); ProxyControl proxy = new ProxyControl(); proxy.setNonGuiTreeModel(treeModel); proxy.setTarget(treeModel.getNodeOf(threadGroup)); proxy.setPort(8282); treeModel.addComponent(proxy, (JMeterTreeNode) root.getChildAt(1)); proxy.startProxy(); HttpHost proxyHost = new HttpHost("localhost", 8282); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); CloseableHttpClient httpclient = HttpClients.custom().setRoutePlanner(routePlanner).build(); try { httpclient.execute(new HttpGet("http://example.invalid")); } catch (Exception e) { // } proxy.stopProxy(); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { SaveService.saveTree(treeModel.getTestPlan(), out); out.close(); System.out.println(out.toString()); } }