Java Swing Components Are Not Thread-Safe in Java

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

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.

You might also like