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 8681273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:27:55+00:00 2026-06-12T21:27:55+00:00

I am trying to learn about thread and find some examples in the internet.

  • 0

I am trying to learn about thread and find some examples in the internet. This is a java class that output “hello, world” every 3 seconds. But I have a feeling that the part about creating a Runable object is redundant.

Instead of writing

Runnable r = new Runnable(){ public void run(){...some actions...}}; 

Can I put the method run() somewhere else for easy reading?

This is what I have:

public class TickTock extends Thread {
    public static void main (String[] arg){
        Runnable r = new Runnable(){
            public void run(){
                try{
                    while (true) {
                        Thread.sleep(3000);
                        System.out.println("Hello, world!");
                    }
                } catch (InterruptedException iex) {
                    System.err.println("Message printer interrupted");
                }
            }
        };
      Thread thr = new Thread(r);
      thr.start();
}

And this is what I want to accomplish

public static void main (String[] arg){ 
          Runnable r = new Runnable() //so no run() method here, 
                                  //but where should I put run()
          Thread thr = new Thread(r);
          thr.start();
    }
  • 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-06-12T21:27:56+00:00Added an answer on June 12, 2026 at 9:27 pm

    Can I put the method run() somewhere else for easy reading?

    Yes you could create your own runnable like this

    public class CustomRunnable implements Runnable{
    // put run here
    }
    

    and then

    Runnable r = new CustomRunnable () ;
    Thread thr = new Thread(r);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to learn something about the thread in WPF this is the
I am trying to learn some more about vectors and rotation in Java by
I'm trying to learn about this feature of javascript I keep seeing in code,
i'm trying to learn about user controls. I created a user control that has
I am trying to learn about all possible conditionals that can be used on
I am trying to learn about the Service class in Android. I have created
I'm trying to learn about java's event handlers and keep getting errors with type
Im am trying to learn some more about vectors and rotation so I can
This is some sample test app i trying to learn Parallel.Foreach Loop functionality static
Just trying to ping up some experienced Thread gurus out there...trying to learn more

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.