| Author |
About using Swing components in SCJD exam
|
Helen Ma
Ranch Hand
Joined: Nov 01, 2011
Posts: 451
|
|
When I read Chatper 4 of Monkhouse book, Swing is not thread safe and it is recommended that a Swing component should be accesed by only one thread.
As far as the exam is a concern, if two threads try to write a string into a JTable cell, should I still synchronized the JTable object?
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4349
|
|
|
Your Swing client is such a simple application. There is no need to have a multi-threaded approach. So it's not an issue at all.
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
Anayonkar Shivalkar
Bartender
Joined: Dec 08, 2010
Posts: 1295
|
|
I agree with Roel De Nijs.
Helen Ma wrote:As far as the exam is a concern, if two threads try to write a string into a JTable cell, should I still synchronized the JTable object?
Well, is it really going to happen? The chances are very high that the String will come from server as part of remote object, and your client will write that String in JTable. I don't see any reason why your client should do it in multi-threaded way.
And secondly, the moment you open another client, there will be completely new GUI, which means the JTable also would be different one.
So, there's no need to worry about thread-unsafety of swing components.
I hope this helps.
|
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
|
 |
 |
|
|
subject: About using Swing components in SCJD exam
|
|
|