SwingWorker is supposed to be constructed in EDT too, and it will go
to background thread pool queue after invoking execute() method. So
you do not need to create different injectors.
If your background SwingWorker wants to do something with swing
components - there is process(List<V> chunks) method, and you have to
design your implementation to do all component processing there.

PS: that's none of my business, but as for me if you have only one
background thread - SwingWorker declares too many rules. You could
create your own implementation with basic synchronization primitives,
make it optimized for your concrete task, without creating that 10-
threads pool and collecting unwanted intermediate results into
accumulative runnables as SwingWorker does.

On Jun 23, 7:11 am, caru <[email protected]> wrote:
> Hi all,
> I am configuring the GUI by instantiating the injector in the "invokeLater"
> method, to make sure all Swing components get instantiated in the EDT.
> The issue is I must define some SwingWorkers which need injection of both a
> Swing component and a background thread object (singleton) , to be used in
> the doInBackground() method.
> Since singletons are instantiated eagerly (at least in production stage),
> the solution I figured out was to use a different injector to instantiate
> such a singleton, which is called in the main method, to make sure the
> singleton actually get instantiated in a thread which is not EDT.
>
> I'd like to have a constructor such as:
> @Inject MySwingWorker(JPanel panel, MyBackgroundThreadInterface
> massiveTaskPerformer) {...}
>
> But this won't work, as MySwingWorker and JPanel are created by the Swing
> injector and the second parameter is provided by a different injector...
>
> To wrap up, I am pretty sure I am overcomplicating the problem... without
> actually solving it :) Do you know a good way to solve this?

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to