java - What happen in Thread program if start() method calls within it's own body? -


Please give me some vivid explanations in this regard. I have tried a lot, but I could not understand it.

I am completely messing with the program's code segment from below, called below in the program like repetition, and even how to start the first method before starting Start method body

Thanks in advance.

  package appletexample; Import java.awt. *; Import java.applet *; Public class appleton extension extends runanble {string str = "this is a simple banner"; Thread T; Boolean B; Public zero init () {setBackground (Color.gray); setForeground (Color.yellow); } Public Zero Start () {T = New Thread (this); B = false; T.start (); } Public run zero () {Four f; (;;) {Try (Paint); Thread.Sleep (200); Ch = str.charAt (0); str = str.substring (1, str.length ()); Str = str + ch; } Grip (Interrupted predefined E) {}}} Public Zero Color (Graphics G) {g.drawRect (1,1,300,150); G.setColor (Color.yellow); G.fillRect (1,1,300,150); G.setColor (Color.red); G.drawString (str, 1, 150); }}   

I'm a newbie for thread concept, please give me a clear picture about this. And to understand the thread concept with applet and web based programming, give me some reference websites

You can not call start () on the thread that has already started, you will get an Invalid Refrigeration Status . However, your program is not doing this.

In your Applet's Start method, you create threads and the applet runnable argument. This means that when the thread starts, it calls the applet's run method, then you call start on the thread to call. But you are calling start () on the thread, not an applet, so you are not accidentally running the applet's own start method here, there are no recycling here. Used to be.


However, you are starting a thread and can never stop it. This is a bad thing. Your applet needs to be cleaned after itself, and even after the applet has destroyed it should not always leave the thread running. The way to do this is:

First of all, run your method to actually answer thread interruption instead of ignoring your exception instead of your hold (blocked exception e) In the block, define a return (see For more information about thread interruptions.)

Second, a stop () Add the method to your applet. Like start () , it is defined in the applet category, and it will be automatically asked when it's time to stop its applet.

Third, in your new stop () method, t.interrupt () followed by t.join () Do it. It will tell the thread that it should stop moving, then wait for it.

Comments

  1. जावा प्रोग्रामिंग कोडर्स के लिए नमूने
    JPEG छवि नमूना बनाना

    ReplyDelete

Post a Comment

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -