Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how continuing running the daemon if one thread throws exception

Posted on 2005-04-08
5
Medium Priority
?
242 Views
Last Modified: 2010-03-31
i have a daemon witch have a list of thread
every thread has one task to do
and has try catch block
if a thread crashes,i want to inform in display the cause of this execption(Exeption e){e.getMessage}
and continuing running the thread in the current state without starting the daemon ,
could u help me please
0
Comment
Question by:laes_
  • 3
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 120 total points
ID: 13734275
so long as the thread doesn't finish it's run() loop, then that should be ok...

can you post your code?

As soon as a thread finishes, it cannot be restarted
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13734397
ie:

public class MyThread extends Thread
{
    // A method which sometimes throws an exception
    public int getNum( int i ) throws IllegalArgumentException
    {
        if( i == 5 )
            throw new IllegalArgumentException( "I don't like the number 5" ) ;
        return i ;
    }

    public void run()
    {
        for( int i = 0 ; i < 10 ; i++ )
        {
            try
            {
                System.out.println( "Processing " + i ) ;
            }
            catch( IllegalArgumentException ex )
            {
                System.out.println( "Caught Exception: " + ex.getMessage() ) ;
            }
        }
    }
}

then:

new MyThread().start() ;
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13734409
Sorry

                System.out.println( "Processing " + i ) ;

should be

                  System.out.println( "Processing " + getNum( i ) ) ;
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question