Hey there! any question in your mind? Ask It Now!.

Popular Categories





Frequently asked java interview written question

+1 vote
47 views
asked in Java Interview Question by Vikaas
Please see below code and find error or bugs :

public class Thread1 {


        private static  boolean interruptedTask=false;

        private static class MyClass extends Thread{

            public void run(){

                while(!interruptedTask){

                //Do some time consuming task for more than 5 secs

                }

            }

        }
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Thread task=new MyClass();
            task.start();

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            interruptedTask=true;
            try {
                task.join();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

    }

Please log in or register to answer this question.

Related Questions

+2 votes
1 answer 205 views
0 votes
0 answers 34 views
0 votes
5 answers 511 views
+2 votes
1 answer 60 views
0 votes
0 answers 56 views
0 votes
0 answers 178 views
+1 vote
2 answers 1,332 views

Not a Member yet?

Ask to Folks Login

My Account
881 Folks are online
80 members and 801 guest online
Your feedback is highly appreciated