Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Design question  RSS feed

 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a small Swing app that has several class that use JDialog and will likely be utilized multiple times during a session.

Is it better to design them with a singleton pattern? It seems like it will speed up things up, but at cost of slightly more constant memory use.

If this is a good way to go, is it better to use synchronize in the method header, or use a semaphore lock around the line that instantiates the class? Does it matter? This is not a performance critical app.

ie:

public synchronized static CLASSNAME getInstance()
{
...
}

or
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm more of a lazy init kind of guy. I'd just load them when you need them and let GC take care of them when you are done.
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronized would be pointless, because you should always be opening dialogs from the main Swing thread. And I agree with Greg, creating a hundred or so dialogs and letting the GC take care of them is no big deal.
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following OK?



Or do I have to make a Runnable and make sure that the option pane runs from the Swing/AWT thread?


[ May 17, 2007: Message edited by: Kaydell Leavitt ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!