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

  • SEARCH
  • Home
  • 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 7662569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:50:03+00:00 2026-05-31T13:50:03+00:00

I have an app where when a game stats, it starts a couple different

  • 0

I have an app where when a “game” stats, it starts a couple different threads. I start the threads like so:

Thread thread = new Thread(new Runnable()
{
    public void run()
    {
        //...
    }
});

thread.setName("killMeAtEnd");
thread.start();

Later when the game ends i have a dispose() method inside of game which sorts through all of the running Threads and ends all of the Threads that have the name “killMeAtEnd”. My question is, is this good practice? My intention is to keep my app running fast and clutter free, in my experience Threads that are left “hanging” tend to slow down the phone until the app is terminated. Is there a better way to do this? Is this even worth bothering about?

EDIT:

Here is my dispose() if anyone was interested. This code is within the class Game.

public void dispose()
{
    Thread threads[] = (Thread[])Thread.getAllStackTraces().keySet().toArray();
    for(int x=0;x<threads.length;x++)
    {
        Thread thread = threads[x];
        if(thread.getName().equalsIgnoreCase(KILL))
        {
            try
            {
                thread.interrupt();
            }catch(Exception e){Log.e(Viewer.GAME,Log.getStackTraceString(e));}
            thread = null;
        }
    }
}

public static final String KILL = "endOnDispose";
  • 1 1 Answer
  • 0 Views
  • 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-31T13:50:05+00:00Added an answer on May 31, 2026 at 1:50 pm

    You have the right idea, but there are some areas for improvement:

    1. Instead of querying the system for all running threads, just add your threads to a list whenever you create them. You can then terminate all the threads you created or wait for their completion (joining).
    2. Interrupt only interrupts a thread in a blocking state, so you need to have an additional flag that the thread checks periodically (i.e. after every “work cycle”).
    3. Catch the interrupt exception inside your thread and handle it (i.e. exit gracefully).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web app game and while in the game I want to
I have an game app which occasionally plays sounds. When the phone goes into
I have a game app which is mostly working fine. If a phone call
I have a Rails app implementing a game, so it's expected that a player
I have created an animated game app, In which I am using NSTimer to
So I have an app where you play a game, and at the end
I am making an example app of a game. I have a folder i
I have an app that starts playing sounds and begins/resumes gameplay in the onResume()
I've written a simple game-like app in WPF. The number of objects drawn is
I have a Cocos2d/openGL iPhone game. It's a universal app and I'm dealing with

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.