• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gui and Threading

 
Pieter Jacobs
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

With my Main GUI, I have implemented Runnable; and then in the class that actually starts up the Main GUI, I created a new Thread and call its start().
(I did not create a new Thread in my Server GUI though).

Is it correct to handle it his way?

Thanks,
Pieter
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't do anything like that. What's the purpose/benefit of your approach?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:I didn't do anything like that.


Me neither.

Champion, the solution is supposed to be simpler than that. Just have a presentation layer that consumes the services defined in your business layer and you'll do well!!!
 
Pieter Jacobs
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Thanks for the replies guys!

I understand that every app should respect synchronization and therefore felt that a Thread needs to be created as part of this?

So in simple terms, do you guys purely start up you GUIs (Client/s & Server) and talk to Data, and that's it? (No creation of a Thread from the Client GUIs)

Thanks,
Pieter
 
Cindy Carney
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that creating a separate GUI thread is the way it's SUPPOSED to be done, actually. That way all your methods get called from within the GUI thread, so there's less of a chance of encountering multithreading problems.

 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pieter Jacobs wrote:So in simple terms, do you guys purely start up you GUIs (Client/s & Server) and talk to Data, and that's it? (No creation of a Thread from the Client GUIs)

Exactly! The main class starts a GUI for the server or a GUI for the client, no seperate threads being started, just a couple of JFrames being created.

Kind regards,
Roel
 
Pieter Jacobs
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel / Cindy / Roberto,

Thanks for the replies!

Cool, enjoy the week,
Pieter
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cindy Carney wrote:I have read that creating a separate GUI thread is the way it's SUPPOSED to be done, actually. That way all your methods get called from within the GUI thread, so there's less of a chance of encountering multithreading problems.

Not entirely true. What you should do is to create an instance of Runnable that calls frame.setVisible(true) and than pass it to the Even Dispatch Thread via SwingUtilities.invokeLater(). Most of the time you don't have to do this and all works, but I read somewhere that some components are not that lenient and you might run into race conditions. Unfortunately, a shallow google search didn't produce any results, but I will try later to back up my claim

Just my 2c.

Raf

EDIT: here is something: http://java.sun.com/javase/6/docs/api/javax/swing/package-summary.html#threading
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic