Results 1 to 18 of 18
  1. #1
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default please answer some basic question if you can

    Hello Developers
    i want to know answer of some question regarding thread.


    1-Which method is used for registering a thread with the thread scheduler ?
    2-is it possible to get daemon thread directly?
    3-When JVM start up,which thread will be started first?
    4-Which thread is not allowed for sleep?
    5-Is there a separate stack for each thread in JAVA?
    6-Is self thread interruption possible?

    if you know the answer of any of the question then please reply
    Thanks

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I believe I can answer some.

    1) I believe creating a new thread and starting it registers it with the scheduler.
    2)
    3) the first thread to be started is the main thread.
    4)I believe all threads can be put to sleep(not confident on this)
    5) yes there is a separate stack for each thread
    6) threads can interrupt themselves I believe.

  3. #3
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    sunde887 is correct on all and #2 is Yes. However, I am a bit hesitant on #3 since I think the ClassLoader thread is first.

  4. #4
    Maximus-EVG is offline Member
    Join Date
    Apr 2011
    Location
    Canada!
    Posts
    30
    Rep Power
    0

    Default

    If on 3) you mean from amongst the user threads, it will be whichever you .start() first. Otherwise, everything looks correct, and I got no idea about 2).

  5. #5
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    @Maximus
    No he's asking the first thread to start when the JVM starts.
    And #2 is Yes: "thread.setDaemon(true)"

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

  7. #7
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Hey, please don't cross post. :(
    This forum is better than that one ;)

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    yay, I was mostly right..my thread knowledge isn't exactly great at the moment. Hopefully he isn't cheating, Im sorry if I just gave him homework answers, it was not intended.

  9. #9
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    sorry for cross posting ,actually i did not read rule
    From now onwards i will follow that
    @sunde887,@ra4king>thanks for ur nice reply

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Glad to help :D

  11. #11
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    @Maximus
    No he's asking the first thread to start when the JVM starts.
    And #2 is Yes: "thread.setDaemon(true)"
    @ra4king>but in this process we are first creating user thread then after that we are modifying as daemon

  12. #12
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    No, the thread hasn't started yet. If you call thread.setDaemon(true) after you call thread.start(), you will get an IllegalThreadStateException.

  13. #13
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    sunde887 is correct on all and #2 is Yes. However, I am a bit hesitant on #3 since I think the ClassLoader thread is first.
    i know that when we trigger java command to run any class file then JVM starts
    three threads "1-main thread, 2-Thread Scheduler, 3-Garbage collector"
    but i don't know among 3 which stats first?

  14. #14
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Well by name, Thread Scheduler sounds like the most obvious one.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sunde887 View Post
    4)I believe all threads can be put to sleep(not confident on this)
    If you put the EDT (Event Dispath Thread) to sleep you'll freeze your Swing application. But it can be put to sleep, there's nothing that can forbid it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    Well by name, Thread Scheduler sounds like the most obvious one.
    yeah i am also thinking the same

  17. #17
    togaurav is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    If you put the EDT (Event Dispath Thread) to sleep you'll freeze your Swing application. But it can be put to sleep, there's nothing that can forbid it.

    kind regards,

    Jos
    well, i am beginner so i do not have knowledge about swing
    i think, we can't put to sleep "thread scheduler" thread because it is handling all operation link scheduling and registering child thread

  18. #18
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    You can put to sleep any thread, but there are some that you *shouldn't*.

Similar Threads

  1. Replies: 12
    Last Post: 07-27-2010, 09:40 AM
  2. Java Interview Question and Answer
    By gnomeom in forum Java Software
    Replies: 3
    Last Post: 06-04-2009, 11:53 AM
  3. How to loop a question when answer is negatve?
    By brazuca in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 05:46 AM
  4. Answer To Previous Question
    By herbozo2003 in forum Java Servlet
    Replies: 0
    Last Post: 03-02-2009, 02:22 AM
  5. Plz answer this question ...
    By raghu2114 in forum Advanced Java
    Replies: 2
    Last Post: 09-19-2008, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •