The Most Efficient Way to Block the main() #java #shorts #coding #airhacks

preview_player
Показать описание
How to block the main method efficiently

Java used in this short: openjdk version "21" 2023-09-19 LTS

#airhacks
Рекомендации по теме
Комментарии
Автор

Technically a system could hook into your program and call "notify" which notifies all the "waiters" to continue.

Fun fact, you can use this system to build a "MainThread" timeout system.

I use it to have the main thread work on a task queue only for a certain amount of time and then free the thread from the queue.
The second thread notifies the timeout thread and then starts working.
if it is done before the timeout thread it will tell it that its done, otherwise the timeout thread will simply interrupt the main thread.

Speiger
Автор

Hey man, one small doubt as the main methid runs on a main thread. Does the thread completely occupies a core . As threads are much more optimised for sharing resources i got this doubt.

kruthiksai