4

When I am working with AWT, after calling the Toolkit.getDefaultToolkit(), I have printed the current running threads in my program. I would like to know what is that AWT-Windows thread that is running in the background. What does it do and why does it have 6 priority.

Also, the line

Thread[AWT-Windows,6,main]

does the main mean that the thread is started in the main thread?

Thanks in advance.

JavaTechnical
  • 8,846
  • 8
  • 61
  • 97

1 Answers1

6

AWT is the Java Abstract Window Toolkit. The AWT thread should be handling all AWT events, rendering, etc...

The 6 priority is just one above normal priority to make this scheduler bias slightly towards it.

main is the group of the thread.

EDIT

The AWT-Windows thread specifically handles polling events from the native Windows C++ API for GUIs. The specific native method that handles the events is sun.awt.windows.WToolkit.eventLoop().

hsun324
  • 549
  • 3
  • 9
  • Then what is the difference between event dispatch thread and this thread? – JavaTechnical Feb 06 '14 at 08:50
  • No they are not same. You can see AWT-EventQueue thread, a thread that is started when a frame is made visible. This thread handles the AWT events. – JavaTechnical Feb 06 '14 at 08:51
  • windows events in the sense? – JavaTechnical Feb 06 '14 at 08:52
  • As in UI/Input events. – hsun324 Feb 06 '14 at 08:53
  • Could you elaborate it? – JavaTechnical Feb 06 '14 at 08:53
  • At a low level, programs that create frames in Windows must have a loop that handles Windows GUI API events. The AWT-Windows thread is basically a native interface to the loop that polls the Windows API event loop for events. – hsun324 Feb 06 '14 at 08:55
  • That means, for example, when a button is clicked as an AWT button uses the native code, the events are sent to that native code and then the AWT-Windows thread interacts with that native code to know what type of event has occured? – JavaTechnical Feb 06 '14 at 08:57
  • So an event is first known by the os before it is detected by the program? – JavaTechnical Feb 06 '14 at 09:00
  • the loop would register a mouse down/mouse up event in the sense, does the OS know that the user pressed on a button or it just knows that the user has pressed at some point? – JavaTechnical Feb 06 '14 at 09:02
  • But when a program is executed, every component is treated as a standard windows object? I am talking only for AWT here. – JavaTechnical Feb 06 '14 at 09:04
  • But we usually say that AWT components uses the native code i.e. the code for GUI components that comes with the operating system? – JavaTechnical Feb 06 '14 at 09:05
  • Then why would we say that AWT is heavy weight and Swing is lightweight? Swing components are coded from the scratch. Also there were classes written in the AWT in sun.awt.windows package. What are these then? Thanks. – JavaTechnical Feb 06 '14 at 09:07
  • 1
    I should delete everything else I have said here. I confused AWT and Swing. Since AWT is heavyweight then the event loop would actually be recieving events corresponding to real native UI components. The `sun.awt.windows` package would be Windows specific code that interfaces with the Windows API. If you were on a different platform, there would be no `sun.awt.windows`. – hsun324 Feb 06 '14 at 09:10
  • 1
    That's ok. But the final words are that the AWT-Windows thread interacts with the Windows operating system to know what event has occured and on which component it has occured and then pass it to the event dispatch thread? Am i right? Thanks. – JavaTechnical Feb 06 '14 at 09:12
  • So, is it right that the Windows os knows that on which component that the user has clicked or just the point? – JavaTechnical Feb 06 '14 at 09:13
  • Because the OS knows that the component is there and that MFC does tell the application about the target of the event, it logically follows that the OS does know that the user used a certain component. – hsun324 Feb 06 '14 at 09:14
  • I think it is just in the case of AWT because only AWT uses native code, but in the swing case that might be different because swing components are built from the scratch? Am i right? – JavaTechnical Feb 06 '14 at 09:15
  • Yes. The OS would only know that the event was meant for a certain window because Swing does not tell the OS anything about the components drawn within the window because Swing handles most of it itself. – hsun324 Feb 06 '14 at 09:16
  • In which class was the code written for interaction with the Windows native API? – JavaTechnical Feb 06 '14 at 09:17
  • I personally do not know. You may be able to figure it out by looking at the trace for the `AWT-Windows` thread. – hsun324 Feb 06 '14 at 09:22
  • Which IDE do you use? – hsun324 Feb 06 '14 at 09:24
  • I do not use IDE, i just use Sublime Text to write programs. I use IDE only for developing apps. – JavaTechnical Feb 06 '14 at 09:25
  • Yeah! Thank you. I got it. It is sun.awt.windows.WToolkit. But i am seeing for more information. – JavaTechnical Feb 06 '14 at 09:26
  • Yes! There is a method called `eventLoop()` in it. It is the method in which all this takes place (as from the output). THANK YOU VERY MUCH!!!!! – JavaTechnical Feb 06 '14 at 09:27
  • Does this thread sleep whenever there is no event and wake up when an event occurs OR just use polling technique which loops to check if there are event(s) occurred? – JavaTechnical Feb 11 '14 at 12:54