MyTextArea(int x, int y, int priority){ setForeground(Color.BLUE); setSize(150,200); setLocation(x,y); Thread writer = new Thread(this); writer.setPriority(priority); writer.start(); }
/** Called by ImageJ when the user selects Quit. */ public void quit() { quitMacro = IJ.macroRunning(); Thread thread = new Thread(this, "Quit"); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); IJ.wait(10); }
public static void startMainThread(String s, String s1, String s2) { boolean flag = false; String s3 = s; Frame frame = new Frame("Minecraft"); Canvas canvas = new Canvas(); frame.setLayout(new BorderLayout()); frame.add(canvas, "Center"); canvas.setPreferredSize(new Dimension(854, 480)); frame.pack(); frame.setLocationRelativeTo(null); MinecraftImpl minecraftimpl = new MinecraftImpl(frame, canvas, null, 854, 480, flag, frame); Thread thread = new Thread(minecraftimpl, "Minecraft main thread"); thread.setPriority(10); minecraftimpl.minecraftUri = "www.minecraft.net"; if (s3 != null && s1 != null) { minecraftimpl.session = new Session(s3, s1); } else { minecraftimpl.session = new Session( (new StringBuilder()) .append("Player") .append(System.currentTimeMillis() % 1000L) .toString(), ""); } if (s2 != null) { String as[] = s2.split(":"); minecraftimpl.setServer(as[0], Integer.parseInt(as[1])); } frame.setVisible(true); frame.addWindowListener(new GameWindowListener(minecraftimpl, thread)); thread.start(); }
public void start() { if (thread == null && !dontThread) { thread = new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.setName(name + " Demo"); thread.start(); } }
public void start() { Dimension size = getSize(); for (int i = 0; i < animpts.length; i += 2) { animpts[i + 0] = (float) (Math.random() * size.width); animpts[i + 1] = (float) (Math.random() * size.height); deltas[i + 0] = (float) (Math.random() * 4.0 + 2.0); deltas[i + 1] = (float) (Math.random() * 4.0 + 2.0); if (animpts[i + 0] > size.width / 6.0f) { deltas[i + 0] = -deltas[i + 0]; } if (animpts[i + 1] > size.height / 6.0f) { deltas[i + 1] = -deltas[i + 1]; } } anim = new Thread(this); anim.setPriority(Thread.MIN_PRIORITY); anim.start(); }
public Thread newThread(Runnable r) { final Thread thread = new Thread(r, "ApplicationImpl pooled thread " + i++) { public void interrupt() { if (LOG.isDebugEnabled()) { LOG.debug("Interrupted worker, will remove from pool"); } super.interrupt(); } public void run() { try { super.run(); } catch (Throwable t) { if (LOG.isDebugEnabled()) { LOG.debug("Worker exits due to exception", t); } } } }; thread.setPriority(Thread.NORM_PRIORITY - 1); return thread; }
public BizSimMain(int numThreads, int numAgents, int numGenerations) { // configure our main window which will contain all the other elements JFrame control_window = new JFrame(); control_window.setTitle("Control Suite"); control_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); control_window.setSize(new Dimension(800, 480)); // control_window.setAlwaysOnTop(true); control_window.setLayout(new BorderLayout()); JPanel species_control = new JPanel(); JLabel species_list_l = new JLabel("Species Running"); DefaultListModel species_list = new DefaultListModel(); // create our Environment Environment e = new Environment(); // create all our threads for (int kittehsex = 0; kittehsex < numThreads; ++kittehsex) { // create some test agents ArrayList<Agent> agents = new ArrayList<Agent>(); for (int i = 0; i < numAgents; ++i) { agents.add(new Agent()); } // create our new thread and pass in some control variables ProcessSimulator ps = new ProcessSimulator(agents, numGenerations, kittehsex, e, this); Thread t = new Thread(ps); species.add(ps); // update our current species list species_list.addElement("Species #" + kittehsex); // set the thread to a high priority, and then start it t.setPriority(9); t.start(); } // create a selectable list of all the different species we have JList species_select_list = new JList(species_list); species_select_list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); species_select_list.setLayoutOrientation(JList.VERTICAL); species_select_list.setVisibleRowCount(3); // start listening to all buttons start_stop.addActionListener(this); reset.addActionListener(this); reconfigure.addActionListener(this); // add mnemonics to some buttons start_stop.setMnemonic('s'); reset.setMnemonic('r'); reconfigure.setMnemonic('e'); // create a panel for all our environment variables JPanel environment_controls = new JPanel(); environment_controls.setBorder(BorderFactory.createTitledBorder("Modify Finished Good Values")); environment_controls.setLayout(new GridLayout(3, 4)); environment_controls.add(new JLabel("High Rate:")); environment_controls.add(high_rate); environment_controls.add(new JLabel("High Sale:")); environment_controls.add(high_sale); environment_controls.add(new JLabel("Med Rate:")); environment_controls.add(med_rate); environment_controls.add(new JLabel("Med Sale:")); environment_controls.add(med_sale); environment_controls.add(new JLabel("Low Rate:")); environment_controls.add(low_rate); environment_controls.add(new JLabel("Low Sale:")); environment_controls.add(low_sale); // create a panel for all our simulation variables JPanel simulation_controls = new JPanel(); simulation_controls.setBorder(BorderFactory.createTitledBorder("Modify Simulation Controls")); simulation_controls.setLayout(new GridLayout(6, 2)); simulation_controls.add(new JLabel("Agent Count:")); simulation_controls.add(agent_count); simulation_controls.add(new JLabel("Generation Count:")); simulation_controls.add(generation_count); simulation_controls.add(new JLabel("Elite Percent")); simulation_controls.add(elite_percent); simulation_controls.add(new JLabel("Parent Percent")); simulation_controls.add(parent_percent); simulation_controls.add(new JLabel("Agent Performance")); simulation_controls.add(agent_performance); // create a panel for displaying information about the current elite // agent JPanel elite_panel = new JPanel(); elite_panel.setBorder(BorderFactory.createTitledBorder("Current Elite Agent Performance")); elite_panel.setLayout(new GridLayout(2, 2)); elite_panel.add(new JLabel("Total: ")); elite_panel.add(cur_elite_total); elite_panel.add(new JLabel("Genome: ")); JScrollPane genome_scroll = new JScrollPane(cur_elite_genome); elite_panel.add(genome_scroll); // this panel encompasses the different panels for altering and showing // the current state of the simulation JPanel field_controls = new JPanel(); field_controls.setLayout(new GridLayout(2, 2)); field_controls.add(environment_controls); field_controls.add(simulation_controls); field_controls.add(elite_panel); // set some attributes on misc. GUI stuff cur_elite_genome.setWrapStyleWord(true); cur_elite_genome.setEditable(false); cur_elite_genome.setLineWrap(true); // set the size of the button to just 3 characters high_rate.setColumns(3); high_sale.setColumns(3); med_rate.setColumns(3); med_sale.setColumns(3); low_rate.setColumns(3); low_sale.setColumns(3); // set the current value of our fields to the current environment value high_rate.setText(e.getHQRate() + ""); high_sale.setText(e.getHQSale() + ""); med_rate.setText(e.getMQRate() + ""); med_sale.setText(e.getMQSale() + ""); low_rate.setText(e.getLQRate() + ""); low_sale.setText(e.getLQSale() + ""); // set the default value of our fields to the current simulation values day_count.setText("100"); generation_count.setText(numGenerations + ""); elite_percent.setText(".05"); parent_percent.setText(".8"); agent_count.setText(numAgents + ""); agent_performance.setText(e.getIncomeRatioThreshold() + ""); // create a panel for all our flow control buttons JPanel control_flow_buttons = new JPanel(); control_flow_buttons.setLayout(new GridLayout(1, 6)); control_flow_buttons.add(start_stop); control_flow_buttons.add(reset); control_flow_buttons.add(reconfigure); // add our components to the window species_control.add(species_list_l); species_control.add(species_select_list); control_window.add(species_control, BorderLayout.WEST); control_window.add(field_controls, BorderLayout.CENTER); control_window.add(control_flow_buttons, BorderLayout.SOUTH); control_window.setLocation(620, 0); control_window.setVisible(true); }
public void start() { Thread me = new Thread(this); me.setPriority(Thread.MIN_PRIORITY); me.start(); }
/** Called by ImageJ when the user selects Quit. */ public void quit() { Thread thread = new Thread(this, "Quit"); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); IJ.wait(10); }
private void watchProcess() { Runnable runnable = new Runnable() { public void run() { try { watch(); } catch (Exception e) { e.printStackTrace(); String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } setErrorMessage(message); } } }; Thread thread = new Thread(runnable); setThread(thread); thread.setPriority(7); thread.start(); if (isShowDialog()) { Thread watcher = new Thread() { public void run() { try { sleep(delay); } catch (InterruptedException e) { return; } if (getErrorMessage() != null) { JOptionPane.showMessageDialog( centeringComp, "Stopped with error:\n" + getErrorMessage()); return; } JProgressBar progressBar = new JProgressBar(0, 100); progressBar.setIndeterminate(true); JButton stopButton = new JButton("Stop"); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getThread() != null) { while (getThread().isAlive()) { TaskManager.getInstance().setCanceled(true); getThread().stop(); try { sleep(500); } catch (InterruptedException e1) { JOptionPane.showMessageDialog(centeringComp, "Could not stop thread."); return; } } // JOptionPane.showMessageDialog( // JOptionUtils.centeringComp(), // "Execution stopped."); } } }); Box b = Box.createVerticalBox(); Box b1 = Box.createHorizontalBox(); b1.add(progressBar); b1.add(stopButton); b.add(b1); // final JTextArea anomaliesTextArea = new JTextArea(); // final TextAreaOutputStream out = new TextAreaOutputStream( // anomaliesTextArea); // // Box b2 = Box.createHorizontalBox(); // JScrollPane scroll = new JScrollPane(anomaliesTextArea); // scroll.setPreferredSize(new Dimension(300, 50)); // b2.add(scroll); // b.add(b2); if (isShowDialog()) { Frame ancestor = (Frame) JOptionUtils.centeringComp().getTopLevelAncestor(); JDialog dialog = new JDialog(ancestor, "Executing...", false); setStopDialog(dialog); dialog.getContentPane().add(b); dialog.pack(); dialog.setLocationRelativeTo(centeringComp); // LogUtils.getInstance().add(out, Level.FINER); while (getThread().isAlive()) { try { sleep(200); if (existsOtherDialog()) { dialog.setVisible(false); } else { dialog.setVisible(true); dialog.toFront(); } // // anomaliesTextArea.setCaretPosition(out.getLengthWritten()); } catch (InterruptedException e) { return; } } // LogUtils.getInstance().remove(out); dialog.setVisible(false); dialog.dispose(); if (getErrorMessage() != null) { JOptionPane.showMessageDialog( centeringComp, "Stopped with error:\n" + getErrorMessage()); } } } }; watcher.start(); } }
public void start() { thread = new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.setName("MemoryMonitor"); thread.start(); }
public void start() { running = true; Thread thread = new Thread(this); thread.setPriority(Thread.MAX_PRIORITY); thread.start(); }
/** * Starts the debugger. The method stops the current debugging (if any) and takes information from * the provided info (containing the class to start and arguments to pass it and name of class to * stop debugging in) and starts new debugging session. * * @param info debugger info about class to start * @exception DebuggerException if an error occures during the start of the debugger */ public void startDebugger(DebuggerInfo info) throws DebuggerException { debuggerInfo = info; if (remoteDebugger != null) finishDebugger(); // S ystem.out.println("startDebugger " + info); // NOI18N // RemoteDebugging support hostName = null; password = null; boolean local = true; if (info instanceof ReconnectDebuggerInfo) { ReconnectDebuggerInfo rdi = (ReconnectDebuggerInfo) info; hostName = rdi.getHostName(); password = rdi.getPassword(); local = false; } else if (info instanceof RemoteDebuggerInfo) { hostName = ((RemoteDebuggerInfo) info).getHostName(); password = ((RemoteDebuggerInfo) info).getPassword(); local = false; } boolean stopOnMain = info.getStopClassName() != null; stopOnMainFlag = stopOnMain; // S ystem.out.println ("ToolsDebugger.startDebugger " + info.getStopClassName ()); // NOI18N // T hread.dumpStack (); synchronizer = new RequestSynchronizer(); // open output window ... super.startDebugger(info); // start & init remote debugger ................................................ // process = null; if (local) { // create process & read password for local debugging // create starting string & NbProcessDescriptor NbProcessDescriptor debugerProcess; if (info instanceof ProcessDebuggerInfo) debugerProcess = ((ProcessDebuggerInfo) info).getDebuggerProcess(); else debugerProcess = ProcessDebuggerType.DEFAULT_DEBUGGER_PROCESS; HashMap map; if (info instanceof ToolsDebugger10Info) { map = Utils.processDebuggerInfo( info, "-debug", // NOI18N "sun.tools.debug.EmptyApp" // NOI18N ); map.put(ToolsDebugger10Type.JAVA_HOME_SWITCH, ((ToolsDebugger10Info) info).getJavaHome()); } else { if (info instanceof ToolsDebugger11Info) { String javaHome11 = ((ToolsDebugger11Info) info).getJavaHome(); if ((javaHome11 == null) || (javaHome11.trim().length() == 0)) { finishDebugger(); throw new DebuggerException(bundle.getString("EXC_JDK11_home_is_not_set")); } map = Utils.processDebuggerInfo( info, "-debug -nojit", // NOI18N "sun.tools.debug.EmptyApp" // NOI18N ); map.put(ToolsDebugger11Type.JAVA_HOME_SWITCH, javaHome11); } else { map = Utils.processDebuggerInfo( info, "-Xdebug", // NOI18N "sun.tools.agent.EmptyApp" // NOI18N ); } } MapFormat format = new MapFormat(map); String s = format.format( debugerProcess.getProcessName() + " " + debugerProcess.getArguments() // NOI18N ); println(s, ERR_OUT); // start process & read password ...................................... try { process = debugerProcess.exec(format); BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream())); password = bufferedreader.readLine(); showOutput(process, ERR_OUT, ERR_OUT); connectInput(process); } catch (java.lang.Exception e) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_create_debuggee")) .format( new Object[] {format.format(debugerProcess.getProcessName()), e.toString()}), e); } if (password == null) { // no reply finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_connect_to_debuggee")) .format(new Object[] {format.format(debugerProcess.getProcessName())})); } if (password.indexOf("=") < 0) { // NOI18N // unexpected reply println(bundle.getString("CTL_Unexpected_reply") + ": " + password, ERR_OUT); showOutput(process, ERR_OUT + STD_OUT, ERR_OUT); finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Unecpected_debugger_reply")) .format(new Object[] {password})); } password = password.substring(password.indexOf("=") + 1); // NOI18N println(bundle.getString("CTL_Password") + ": " + password, ERR_OUT); hostName = "127.0.0.1"; // NOI18N } // end of local debugging specific else if (info instanceof ReconnectDebuggerInfo) { println(bundle.getString("CTL_Reconnecting"), ERR_OUT | STD_OUT); } else println(bundle.getString("CTL_Connecting_to") + ": " + hostName + ":" + password, ERR_OUT); // start RemoteDebugger ................................................... try { remoteDebugger = new RemoteDebugger( hostName, password.length() < 1 ? null : password, new ToolsCallback(this), isShowMessages()); } catch (java.net.ConnectException e) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_connect_to_debuggee")) .format(new Object[] {e.toString()}), e); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; // e.printStackTrace (); finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_connect_to_debuggee")) .format(new Object[] {e.toString()}), e); } // create arguments for main class ............................................... mainClassName = info.getClassName(); RemoteClass cls; String[] args = null; if ((mainClassName != null) && (mainClassName.length() > 0)) { String[] infoArgs = info.getArguments(); args = new String[infoArgs.length + 1]; args[0] = mainClassName; System.arraycopy(infoArgs, 0, args, 1, infoArgs.length); // args[0] = name of class // args[...] = parameters // find main class ......................................................... try { cls = remoteDebugger.findClass(mainClassName); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_class")) .format(new Object[] {mainClassName, e.toString()}), e); } if (cls == null) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_class")) .format(new Object[] {mainClassName, new ClassNotFoundException().toString()})); } } // set breakpoint on stop class method ............................................... if (stopOnMain) { RemoteClass stopClass = null; try { stopClass = remoteDebugger.findClass(stopClassName = info.getStopClassName()); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; println( bundle.getString("MSG_Exc_while_finding_class") + stopClassName + '\n' + e, ERR_OUT); } if (stopClass == null) { println(bundle.getString("CTL_No_such_class") + ": " + stopClassName, ERR_OUT); } else { try { RemoteField[] rf = stopClass.getMethods(); int i, k = rf.length; Type t = Type.tMethod(Type.tVoid, new Type[] {Type.tArray(Type.tString)}); Type startT = Type.tMethod(Type.tVoid); RemoteField startM = null; RemoteField initM = null; RemoteField constM = null; for (i = 0; i < k; i++) { if (rf[i].getName().equals("main") && // NOI18N rf[i].getType().equals(t)) break; else if (rf[i].getName().equals("start") && // NOI18N rf[i].getType().equals(startT)) startM = rf[i]; else if (rf[i].getName().equals("init") && // NOI18N rf[i].getType().equals(startT)) initM = rf[i]; else if (rf[i].getName().equals("<init>") && // NOI18N rf[i].getType().equals(startT)) constM = rf[i]; } if (i < k) // [PENDING] stop on non main too !!!!!!!!!!!!!!!!!!!!! stopClass.setBreakpointMethod(rf[i]); // have main else if (initM != null) stopClass.setBreakpointMethod(initM); else if (startM != null) stopClass.setBreakpointMethod(startM); else if (constM != null) stopClass.setBreakpointMethod(constM); // S ystem.out.println ("Stop: " + (i <k) + " " + initM +" " + startM +" " + constM); // // NOI18N /* pendingBreakpoints = new RemoteField [1]; pendingBreakpoints [0] = rf[i]; pendingBreakpointsClass = stopClass;*/ } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; println(bundle.getString("MSG_Exc_while_setting_breakpoint") + '\n' + e, ERR_OUT); } } } // stopOnMain setBreakpoints(); updateWatches(); println(bundle.getString("CTL_Debugger_running"), STL_OUT); setDebuggerState(DEBUGGER_RUNNING); // run debugged class ............................................... if (args != null) { RemoteThreadGroup rtg = null; try { rtg = remoteDebugger.run(args.length, args); // threadGroup.setRemoteThreadGroup (rtg); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_calling_run")) .format(new Object[] {mainClassName, e.toString()}), e); } if (rtg == null) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_calling_run")) .format( new Object[] { mainClassName, "" // NOI18N })); } } // start refresh thread ................................................. if (debuggerThread != null) debuggerThread.stop(); debuggerThread = new Thread( new Runnable() { public void run() { for (; ; ) { try { Thread.sleep(5000); } catch (InterruptedException ex) { } if (getState() == DEBUGGER_RUNNING) try { threadGroup.threadChanged(); } catch (Throwable e) { if (e instanceof ThreadDeath) throw (ThreadDeath) e; if (e instanceof java.net.SocketException) { debuggerThread = null; try { finishDebugger(); } catch (Throwable ee) { if (ee instanceof ThreadDeath) throw (ThreadDeath) ee; } Thread.currentThread().stop(); } } } } }, "Debugger refresh thread"); // NOI18N debuggerThread.setPriority(Thread.MIN_PRIORITY); debuggerThread.start(); }
/** * Invoked when one of the menus is selected. * * @param e contains the selected menu item. */ public void actionPerformed(ActionEvent e) { Thread thread = new Thread(this); thread.setPriority(Resource.getThreadPriority()); thread.start(); }