Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:15:55+00:00 2026-05-15T09:15:55+00:00

I have got a problem here in terminating the threads. The problem is that

  • 0

I have got a problem here in terminating the threads. The problem is that I am using applet thread to access JS DOM and manipulate innerHTML of a span to right the Thread Name as the innerHTML. It works fine until I keep refreshing the page but if I dont give it a sleep of like 200ms and go to another page which dont have any applet on it, it will give me an error in firebug console:

document.getElementById("userName") is null

What I am suspecting is, although I send an interrupt on stop and I have also tried the same by setting a flag variable of running in run while loop, the thread executes much faster than the time JVM takes to unload it and I get my page changed in browser but applet is still trying to find an element with id userName.

Is that true?
Is there any work around of it?
Is there any way to know how many threads are running at the moment?
Is there any kill all command to send on destroy()?

I have searched a lot, seen all the API of java threads and applets, couldn’t get this to work.

Below is the code:

import java.applet.Applet;
import netscape.javascript.*;

//No need to extend JApplet, since we don't add any components;
//we just paint.
public class firstApplet extends Applet {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    firstThread first;
    boolean running = false;

    public class firstThread extends Thread{
        JSObject win;
        JSObject doc;
        firstThread second;

        public firstThread(JSObject window){
            this.win = window;
        }
        public void run() {
            try{
                System.out.println("running... ");

                while (!isInterrupted()){

                    doc = (JSObject) win.getMember("document"); 
                    String userName = Thread.currentThread().getName();
                    //String userName = "John Doe";
                    String S = "document.getElementById(\"userName\").innerHTML = \""+userName+"\";";
                    doc.eval(S);
                    Thread.sleep(5);
                }
            }catch(Exception e){
                System.out.println("exception in first thread... ");
                e.printStackTrace();
            }
        }
    }

    public void init() {
        System.out.println("initializing... ");
    }

    public void start() {
        System.out.println("starting... ");
        JSObject window = JSObject.getWindow(this);

        first = new firstThread(window);
        first.start();
        running = true;
    }

    public void stop() {
        first.interrupt();
        first = null;
        System.out.println("stopping... ");
    }

    public void destroy() {
        if(first != null){
            first = null;
        }
        System.out.println("preparing for unloading...");
    }
}

Thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:15:56+00:00Added an answer on May 15, 2026 at 9:15 am

    This problem was solved, using JS variables to control Java applet execution, the complete solution is here: http://ciitronian.com/blog/programming/time-efficiency-controlling-java-applet-from-javascript-especially-if-you-make-round-trips-to-the-web-page-from-applet/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Positioning of floats is funny. Basically, the main div is… May 15, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer You don't want system(3) for that. Try popen(3) and friends. May 15, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer $('#myDropDown').change(function() { if($(this).val() == 4) { $('#dateCell').hide(); } else if($(this).val()… May 15, 2026 at 7:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.