0% found this document useful (0 votes)
34 views6 pages

Java Swing Components Are Not Thread-Safe in Java.: Main Is Run Method Is Completed Whereas Runs The Rest of Code

Java Swing components are not thread-safe due to the overhead of locking and state restoration. They are designed to simplify extension. While not fully thread-safe, some methods like repaint() support multi-threading. Swing components are lightweight as they do not depend on native system classes. InvokeAndWait() executes on the event thread and waits for completion, while invokeLater() also executes on the event thread but continues other processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

Java Swing Components Are Not Thread-Safe in Java.: Main Is Run Method Is Completed Whereas Runs The Rest of Code

Java Swing components are not thread-safe due to the overhead of locking and state restoration. They are designed to simplify extension. While not fully thread-safe, some methods like repaint() support multi-threading. Swing components are lightweight as they do not depend on native system classes. InvokeAndWait() executes on the event thread and waits for completion, while invokeLater() also executes on the event thread but continues other processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2)Does Swing is thread-safe?

Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ansinit()
: It is a lightweight component because it will not depend on any native system
class. init() Applet
Applet
born
5)What
Begin is the difference between
Applet invokeAndWait and invokeLater?
born
Begin Applet
start()
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to eventstop()
start() thread and waits till the execution of
stop()
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.
Applet Applet
2)Does Swing is thread-safe? Applet
running Applet
idle
running
Ans : No, Java Swing components are not thread-safe in Java.
idle
start() destroy ()
 One of the main reason for Java Swing is not thread-safe is to simplify thedestroy
start() task of ()
extending its components.
 Applet
Another reason for the Java Swing is not thread-safe due to the overhead involved
End of Applet
in obtaining and releasing locks and restoring the state.destroyed
End of
Applet
 Some of the Java Swing component destroyed
Applet methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing components are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

2)Does Swing is thread-safe?


Ans : No, Java Swing coRegarding the case where an applet is loaded from the
client’s local disk, the applet is loaded by the file system loader. Applets loaded via the
file system are allowed to read files, write files and to load libraries on the client. Also,
applets loaded via the file system are allowed to execute processes and finally,
applets loaded via the file system are not passed through the byte code verifier.

8)What is the applet class loader, and what does it provide ?

When an applet is loaded over the internet, the applet is loaded by the applet
classloader. The class loader enforces the Java name space hierarchy. Also, the class
loader guarantees that a unique namespace exists for classes that come from the
local file system, and that a unique namespace exists for each network source. When
a browser loads an applet over the net, that applet’s classes are placed in a private
namespace associated with the applet’s origin.

9) What is the applet security manager, and what does it provide ?

The applet security manager is a mechanism to impose restrictions on Java applets. A


browser may only have one security manager. The security manager is established at
startup, and it cannot thereafter be replaced, overloaded, overridden, or extended.

10) How do you set security in applets?

using setSecurityManager() method

11) How will you communicate between two appltes?

java.applet.AppletContext class provides the facility of communication between


applets.

12) What is the sequence of interpretation, compilation of a java applet?

mponents are not thread-safe in Java.

 One of the main reason for Java Swing is not thread-safe is to simplify the task of
extending its components.
 Another reason for the Java Swing is not thread-safe due to the overhead involved
in obtaining and releasing locks and restoring the state.
 Some of the Java Swing component methods will support multi-threaded access
like repaint(), revalidate(), and invalidate() methods of JComponent class.
4)Why Swing components are called lightweight components?
Ans : It is a lightweight component because it will not depend on any native system
class.
5)What is the difference between invokeAndWait and invokeLater?
Ans : Main difference between invokeAndWait() and invokeLater()
is invokeAndWait() keeps the code on to event thread and waits till the execution of
run method is completed whereas invokeLater() keeps the code on event thread and
runs the rest of code in the thread.

You might also like