Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #272

Re: How Do I Make My Appl

From "Steve W. Jackson" <steve.w..jackson@THRWHITE.remove-dii-this>
Subject Re: How Do I Make My Appl
Message-ID <stevewjackson-39F1D5.08592430112006@individual.net> (permalink)
Newsgroups comp.lang.java.gui
References <1164895786.940642.122240@n67g2000cwd.googlegroups.com>
Date 2011-04-27 15:26 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
In article <1164895786.940642.122240@n67g2000cwd.googlegroups.com>,
 "Jason Cavett" <jason.cavett@gmail.com> wrote:

[ snip ]

> 
> So, I attempted to create a thread in my actionPerformed with the
> following code:
> 
> Thread appThread = new Thread() {
> 	public void run() {
> 		try {
> 			model.openProject();
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 
> 	}
> };
> 
> appThread.run();
> 
> 
> However, the menu still seems a little sluggish.  Am I approaching this
> the right way?  (I was never very strong with Threads, so things get a
> little fuzzy here for me.)

When you call the run method of a Thread object, it simply executes in 
line just like any other method.  Instead, call "appThread.start()" in 
your code, which causes the Thread object to run in its own separate 
thread -- which was your goal.  Then appThread will exist independently 
of your actionPerformed method and the EDT on which it was invoked, and 
will become eligible for garbage collection when its run method 
completes.

Alternatively, you could create a Runnable instead of a Thread.  If you 
actually want to spawn it separately, you can then pass that Runnable as 
the parameter to a Thread constructor and call start on the Thread.  But 
if you should need, as I did in some situations, to have it run on the 
EDT, you could pass that Runnable to EventQueue.invokeLater.

= Steve =
-- 
Steve W. Jackson
Montgomery, Alabama

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How Do I Make My Applicat "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: How Do I Make My Appl "david" <david@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: How Do I Make My Appl "Steve W. Jackson" <steve.w..jackson@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
    Re: How Do I Make My Appl "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
      Re: How Do I Make My Appl "Steve W. Jackson" <steve.w..jackson@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
        Re: How Do I Make My Appl "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: How Do I Make My Appl "steve" <steve@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: How Do I Make My Appl "Timasmith" <timasmith@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: How Do I Make My Appl "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web