Andrei
Andrei

Reputation: 7617

What is the purpose of this thread

What is the purpose of thisThread created after all the gui components are initialised? The first few lines are typical boiler plate code when a new GUI is started, but I'm struggling to understand why this thread is started. Found this in an open source project, and I'm wondering why someone would do this.

public static void main( String args[] ) {

    java.awt.EventQueue.invokeLater( new Runnable() {

        public void run(){

            // initialises gui components
            new SchemaRegistrationVisualizer();

            final Thread thisThread = new Thread( new Runnable(){

                public void run(){

                    long startTime = System.currentTimeMillis();

                    while( System.currentTimeMillis() - startTime < Math.pow( 10, 5 ) );

                    System.exit( 0 );
                }
            });

            thisThread.setPriority( Thread.MAX_PRIORITY ); thisThread.start();
        }
    });
}

Upvotes: 0

Views: 82

Answers (2)

KDP
KDP

Reputation: 1481

  • after invoking new SchemaRegistrationVisualizer(), the thread waits for 100000 ms /100s and then exit the jvm
  • The thread has been given max_priority,so the intention to stop the jvm after 100s seems high

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691993

Well, it creates a busy loop that makes one of the CPU cores of the machine go to 100% for 100 seconds, and then exits the JVM.

Upvotes: 4

Related Questions