views:

730

answers:

7

Most modern apps provide an interactive way to push a long running operation onto a background queue. I am developing a swing application and I have implemented a simple "framework" to support that. However, I can't help but think that something like that must exist already. I have heard that Netbeans provides that, but I don't want to migrate my whole app to a new framework (besides, I use eclipse).

Here is a webstart demo of what I am talking about:

ribframework

So, does such a library exist or only within some huge framework?

A: 

Threading is easy enough in Java that I've always just "rolled my own" background processes for smaller projects ... bigger projects usually get an application server of some sort anyways.

Steve Moyer
+7  A: 

Have you looked at the SwingWorker in Java 6?

l_39217_l
A: 

Java5 brought us the wonders of Executors Java6 has finally included SwingWorker

Between the two of them is should be easy to make a simple "run in the background". I don't think you need a framework. Do you have specific requirements or just going for reuse of external code?

basszero
A: 

A former coworker of mine came up with a solution he called "SwingProxy." It was published in a few magazines and there are a few online articles about it, such as this one:

http://java.sys-con.com/node/325197

The basic idea here is that you use his utility class (code provided in link) to create 2 'proxy' objects, 1 for the business logic (stuff to be done in background) and one for the GUI. The business logic class never accesses the GUI directly, it must go through the proxy. Same thing for the GUI. The proxy class has logic to move the calls onto the correct thread.

It definitely adds to the complexity because you need to define extra interfaces for your classes, but I think it's probably simpler than porting your code to a huge framework.

Outlaw Programmer
+4  A: 

The Swing Application Framework can provide you some of the tools necessary to build what you are talking about.

It is actually what Netbeans uses if you use the GUI builder to build your application user interface. We have built a couple of application using Eclipse as our IDE and using that framework to provide access to simple resource usage, basic window configuration restoration like remembering the location of a window between launches, and providing a way to allow for background tasks to run.

Jay R.
A: 

I know all about SwingWorker, in fact, my miniframework uses it. I guess I shouldn't have asked for a library but rather a widget. But it seems like everyone just rolls their own or goes with the big app frameworks...

Maybe I'll publish my little "framework" for others to use someday.

jmagica
I'm interested in your framework. I'm also rolling my own.
tuler
Can you create a web start demo so I can have a look?
jmagica
A: 

Take a look at JSR 296 (Application Framework). It has built in handling for some simple widgets, plus hooks for implementing much more advanced wait/cancel interfaces.

For back-end stuff, I recommend taking a look at Spin as an alternative to SwingWorker (it's not necessarily better - but it is more appropriate in a lot of situations).

Followup based on comments:

If you haven't tried JSR 296's task system, I highly recommend that you do - I think you'll be surprised at how nicely it interacts with widgets, etc... In particular, look at the block parameter of the @Action tag. This is fully extensible, and allows for creation of some very powerful background task handling.

Kevin Day
I know about JSR 296 and I might use it, but I'd rather wait until officially published. Spin looks interesting, I'll have a look.
jmagica