Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Thom Yorke raps
Nov 2, 2004


Hidden Under a Hat posted:

Sorry I hate to quote my own question, but I really would appreciate any insight to this issue, even if it's to say that it doesn't matter if I have one class that is 10,000 lines long. Does that matter or should I really be finding a way to delegate some of the stuff in my main class to another class?

Refactor it, break it into smaller pieces of functionality that make sense. Make sure you have tests so it doesn't break.

Adbot
ADBOT LOVES YOU

Ulio
Feb 17, 2011


I am new to java just began a few days ago. So I was going through this book which is like a guide through java. I need to write a program which asks the user a number(int) and it then tells them if it's even or odd. And this has to use the remainder operator.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Ulio: Did you have a question?

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Ulio posted:

I am new to java just began a few days ago. So I was going through this book which is like a guide through java. I need to write a program which asks the user a number(int) and it then tells them if it's even or odd. And this has to use the remainder operator.

So what is the question?

Also, the remainder operator is the modulo operator (normally called the mod operator).

e: ignore that, forgot is actually called the remainder operator in Java because the way it handles negatives, most people I know (me) call it mod still

lamentable dustman fucked around with this message at 23:26 on Jun 29, 2011

Ulio
Feb 17, 2011


I just don't understand how to write it all. Not much of question but could someone point me in the right way. I never used the % so I don't know how to go about it.

Ulio fucked around with this message at 00:51 on Jun 30, 2011

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Ulio posted:

I just don't understand how to write it all. Not much of question but could someone point me in the right way. I never used the % so I don't know how to got about it.

Well it gives the remainder of a division operation

5 % 3 = 2
6 % 3 = 0
7 % 3 = 1

Ulio
Feb 17, 2011


Ok thanks I got it after this.

This is what I wrote, seems to work
code:
	if(num1 % 2 == 0)
		{
		System.out.print("Number is even");
		}
		else
		{
			System.out.print("Number is odd");
		}

epswing
Nov 4, 2003

Soiled Meat

Ulio posted:

Ok thanks I got it after this.

This is what I wrote, seems to work

Success!

Although the readability of your code needs some work. Readability is very important, even though it looks like it doesn't matter in this small example. When you've written a larger program, and you want someone else to read/debug it, it helps immensely if all your brackets and indented code lines up nicely. Like this:

code:
	if (num1 % 2 == 0)
	{
		System.out.print("Number is even");
	}
	else
	{
		System.out.print("Number is odd");
	}
or this:

code:
	if(num1 % 2 == 0) {
		System.out.print("Number is even");
	}
	else {
		System.out.print("Number is odd");
	}
e: or this (thanks Adeptus):

code:
	System.out.print((num1 % 2 == 0) ? "Number is even" : "Number is odd");

epswing fucked around with this message at 04:47 on Jun 30, 2011

Adeptus Mechanicus
Oct 9, 2007

Ulio posted:

Ok thanks I got it after this.

This is what I wrote, seems to work
code:
	if(num1 % 2 == 0)
		{
		System.out.print("Number is even");
		}
		else
		{
			System.out.print("Number is odd");
		}

If you are comfortable with the ternary operator, this would be a great place to use it to improve readability.

Either way congratulations on getting this working.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Okay, so I'm terrible at GUIs.

How do I communicate between a GUI object and another object?

My specific scenario:
I have a Swing GUI that takes a screenshot of the screen and lets a user select part of it. When the OK button is hit, I need to tell another (non-GUI) object "Here is the coordinate Rectangle" and close the GUI.

But I have no idea how to do this properly and don't know what to look for.

Edit: My current solution is to give the JFrame object an isLiving() method, which just returns whether it hasn't been disposed of or not (by checking an instance boolean that is set to false on dispose). So, in my middle-man object that sits in between the GUI and the object that needs coordinates:
code:
	public Rectangle getCoordinates() {
		while (gui.isLiving()) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return gui.getCoordsCopy();
	}
Am I overlooking anything particularly important? I don't really code anything with a GUI or using threads so I'm not sure if I'm doing it all right.

Malloc Voidstar fucked around with this message at 13:41 on Jun 30, 2011

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
You could try a JDialog with the Modal property set to true. Execution of the parent frame pauses until the dialog is disposed of. CropDialog is the dialog you're doing the selecting in.

code:
CropDialog dialog = new CropDialog(Image image);
dialog.setModal(true);
dialog.setVisible(true);
//Program pauses here while dialog is running
Rectangle rect = dialog.getCoordinates();

Ensign Expendable fucked around with this message at 19:10 on Jun 30, 2011

baquerd
Jul 2, 2007

by FactsAreUseless

epswing posted:

code:
	if (num1 % 2 == 0)
	{
		System.out.print("Number is even");
	}
	else
	{
		System.out.print("Number is odd");
	}

You missed a common one:

code:
	if (num1 % 2 == 0) {
		System.out.print("Number is even");
	} else {
		System.out.print("Number is odd");
	}

Paolomania
Apr 26, 2006

Aleksei Vasiliev posted:

Okay, so I'm terrible at GUIs.

What you proposed is essentially polling for the GUI's exit. Although this can be done, in general GUIs and other programs that are decomposed into discrete components are driven by events that come to objects from external sources (such as the user or another GUI component), rather than internal control flows within each object that peek at bits and decide what to do. So you would have something like:

1. The parentObject spawns the GUI and waits
2. GUI does what it needs to do and computes a value
3. GUI notifies the parentObject that the value is ready
4. The parentObject reads the value and then destroys the GUI

or maybe


1. The parentObject spawns the GUI and waits
2. GUI does what it needs to do and computes a value
3. GUI sends the value to the parentObject and exits
4. The parentObject receives the value and continues

There are a few ways to do this, depending on the structure of your program and how you want to handle things like synchronization. Using Swing determines a few things, because Swing has its own singular event thread, so depending on how you implement your callbacks you may need to spawn new threads. For instance, one event-like implementation I can imagine:

1. parentObject spawns GUI and the current control flow ends
2. GUI (on Swing thread) computes a value
3. GUI spawns a new thread that calls a callback on the parentObject with the computed value
4. parentObject processes value on new control flow

or another way

1. parentObject spawns GUI and waits on a condition
2. GUI (on Swing thread) computes value
3. GUI calls notification method on parentObject
4. parentObject reads value and destroys GUI

Ulio
Feb 17, 2011


Ok thanks on the advices, really helpful, I will post again here when I write a more complex app.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
code:
	private final ExecutorService pool = Executors.newFixedThreadPool(5);

		/* ... */

		CompletionService<Boolean> comp = new ExecutorCompletionService<Boolean>(pool);
		List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
		for (int i = 0; i < files.length; i++) {
			File infile = files[i];
			File outfile = new File(outdir, infile.getName());
			tasks.add(new CrushTask(crusher, infile, outfile));
		}
		for (Callable<Boolean> t : tasks)
			comp.submit(t);
		for (int i = 0; i < files.length; i++) {
			try {
				boolean res = comp.take().get();
				System.out.println(res);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
This code only half works. It's optimizing PNG files by spawning up to 5 instances of pngout.exe, running on a directory of PNG files. Every one of them does get optimized, that isn't the problem.
The problem is that some images take a loong time to compress, 30+ seconds. Most take <5. Whenever it runs into an image that takes a long time, it stops spawning new pngout instances, so I end up with one thread running and four doing nothing at all. Isn't the entire point of an ExecutorService that the other threads can keep working? What am I doing wrong here?

It still cuts 40% or so off the single-threaded time, but it could be doing a lot better.

Ulio
Feb 17, 2011


So I am back again asking for some direction, I need to write an app, where the user inputs a 5 digit number, the system then prints the number with three spaces between each number. So if the user enters 12345 we would see 1 2 3 4 5
It says I should use the division and operand but so far I haven't got a clue how to make this happen.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Aleksei Vasiliev posted:

...

Probably unrelated, but instead of adding an array of callables one-by-one to a CompletionService, you can just use ExecutorService.invokeAll().

Ulio posted:

So I am back again asking for some direction, I need to write an app, where the user inputs a 5 digit number, the system then prints the number with three spaces between each number. So if the user enters 12345 we would see 1 2 3 4 5
It says I should use the division and operand but so far I haven't got a clue how to make this happen.

There are two ways of doing this:

1. The way the assignment says you should do it.
2. The non-stupid way.

The assignment is asking you to:

1. Parse the user input into an integer
2. Use modulo and division to get the individual digits
3. Print them out separated by spaces

I assume you've got part 1 working.

Part 2 is asking you to convert an integer into a string in a particular base. There are a bunch of patterns for doing this, but the basic idea is:

The rightmost digit is n % b
The next digit to the left is (n / b) % b
The digit to the left of that is (n / b^2) % b
And so on....

The non-stupid way is of course to get the digits straight from the string the user provides, instead of turning it into an integer and back again.

Ulio
Feb 17, 2011


Thanks Jabor, I am working on it right now.

I wrote an exercise application a few days ago. Which asks the user three ints then shows the user the smallest int, the largest, the product, the average and the sum.

I did make it work but would like to know if there is a shorter way to find out which is the smallest and largest this how I did it.

code:
              if(num1 > num2)
		    if(num1 > num3)
		    if(num2 > num3)
		    {
		    	System.out.printf("Largest is %d\n", num1);
		    	System.out.printf("Smallest is %d\n", num3);
		    }
			if(num1 > num2)
			if(num1 > num3)
			if(num3 > num2)
		    {
			    	System.out.printf("Largest is %d\n", num1);
			    	System.out.printf("Smallest is %d\n", num2);
		    }
			  
I did this for each possibility so it was lots of copying and pasting. I just want to know if there is another way(pretty sure there is), but not something too advanced. Thanks.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Jabor posted:

Probably unrelated, but instead of adding an array of callables one-by-one to a CompletionService, you can just use ExecutorService.invokeAll().
That doesn't provide the same behavior, though. The CompletionService will return results in the order that they finish, invokeAll blocks until every result has been computed and then returns them in insertion order.

e: also I used that before I tried using the CompletionService and still had the same issue. Totally forgot to mention that part

Malloc Voidstar fucked around with this message at 01:56 on Jul 4, 2011

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Ulio posted:

I did this for each possibility so it was lots of copying and pasting. I just want to know if there is another way(pretty sure there is), but not something too advanced. Thanks.

Suppose that, instead of knowing ahead of time how many numbers you were comparing, you were just given a bunch of them in an array and had to pick out the largest and the smallest. How would you go about doing that?

Luminous
May 19, 2004

Girls
Games
Gains

Aleksei Vasiliev posted:

code:
	private final ExecutorService pool = Executors.newFixedThreadPool(5);

		/* ... */

		CompletionService<Boolean> comp = new ExecutorCompletionService<Boolean>(pool);
		List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
		for (int i = 0; i < files.length; i++) {
			File infile = files[i];
			File outfile = new File(outdir, infile.getName());
			tasks.add(new CrushTask(crusher, infile, outfile));
		}
		for (Callable<Boolean> t : tasks)
			comp.submit(t);
		for (int i = 0; i < files.length; i++) {
			try {
				boolean res = comp.take().get();
				System.out.println(res);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
This code only half works. It's optimizing PNG files by spawning up to 5 instances of pngout.exe, running on a directory of PNG files. Every one of them does get optimized, that isn't the problem.
The problem is that some images take a loong time to compress, 30+ seconds. Most take <5. Whenever it runs into an image that takes a long time, it stops spawning new pngout instances, so I end up with one thread running and four doing nothing at all. Isn't the entire point of an ExecutorService that the other threads can keep working? What am I doing wrong here?

It still cuts 40% or so off the single-threaded time, but it could be doing a lot better.

Can doesn't mean they will. A simple example would be a task that uses a resource that can only be utilized by one thread at a time - using an executor of multiple threads with such a task wouldn't accomplish much. That doesn't seem to be the case here at first glance, although who knows what is going on in CrushTask.

How are you verifying that all other threads are idle when one thread hits a "long image"?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Luminous posted:

How are you verifying that all other threads are idle when one thread hits a "long image"?
Only one pngout process is open, viewing in Task Manager. The instant it finishes, five new ones are spawned.
CrushTask is just this:
code:
	@Override
	public Boolean call() {
		return crusher.compress(input, output);
	} //plus a constructor etc. to store crusher, input, output
The PNGCrusher is creating the commandline for pngout, spawning it (ProcessBuilder), reading its inputstream until it ends*, then returning true if the exit value is a good one. Once pngout ends, the thread just needs to return true or false, there's no other work being done.
The crusher is shared among all the CrushTasks but using a unique one for each task doesn't fix the issue. The only state it has is a final File defining where pngout is.

*: waitFor() hangs forever, so I read the InputStream until it ends and then use exitValue(). I could use waitFor after reading the InputStream (since that prevents the hang) but it's pointless.

I'll post all the code if I need to but it's pretty bad right now.

edit: While only one thread is active, all of the threads are in the Runnable state, locked by an InputStreamReader that's reading the pngout instance's input stream. Also now I know how to do a thread dump.
So I guess I have to figure out how to make it not hang on trying to get the exit value.

e2: Fixed it... for a given value of fixed.
Instead of using this to get the exit value of a Process:
code:
    private static int discardStdOut(Process proc) throws IOException {
        final InputStream is = proc.getInputStream();
        try {
            while (is.read() != -1)
                continue;
            return proc.exitValue();
        } finally {
            close(is);
        }
    }
I'm using this:
code:
    private static int discardStdOut(Process proc) {
        int ret = -1;
        while (true) {
            try {
                ret = proc.exitValue();
                break;
            } catch (IllegalThreadStateException e) {
                sleep(100); // Thread.sleep but eats the exception
            }
        }
        return ret;
    }
Ugh. But now it always has 5 processes going at once.

Malloc Voidstar fucked around with this message at 07:10 on Jul 4, 2011

Luminous
May 19, 2004

Girls
Games
Gains
You should use waitFor if you want to block until the process ends, which is what your second method there is essentially doing, just in a roundabout way.

If you need to consume the standard output (you probably should, as it can lead to blocks if you don't, unless you know pngout has no output) then 1) you should be consuming standard error as well and 2) you need to do this in a concurrent manner (read the stdout and stderr both from separate threads).

Kicking off the stream reads should happen before the waitFor call.

Here's some brief but extended reading:
http://stackoverflow.com/questions/1088941/java-reading-standard-output-from-an-external-program-using-inputstream
http://stackoverflow.com/questions/611760/java-inputstream-read-blocking

Luminous fucked around with this message at 14:40 on Jul 4, 2011

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Luminous posted:

You should use waitFor if you want to block until the process ends, which is what your second method there is essentially doing, just in a roundabout way.

If you need to consume the standard output (you probably should, as it can lead to blocks if you don't, unless you know pngout has no output) then 1) you should be consuming standard error as well and 2) you need to do this in a concurrent manner (read the stdout and stderr both from separate threads).

Kicking off the stream reads should happen before the waitFor call.
I can't use waitFor without consuming the entire stdout. If I call waitFor before that, then it will block forever. The pngout process will eventually go to 0% CPU usage and just sit there doing nothing until I terminate my program. But if I consume the stdout, then the thread will lock, hurting performance a lot.

I am consuming stderr, it's redirected to stdout. Yay ProcessBuilder.

The only output I need from pngout is the exit value, I'm running it in quiet mode anyway.

e: tested and edited to represent reality

Malloc Voidstar fucked around with this message at 14:45 on Jul 4, 2011

Luminous
May 19, 2004

Girls
Games
Gains

Aleksei Vasiliev posted:

I can't use waitFor without consuming the entire stdout. If I call waitFor before that, then it will block forever. The pngout process will eventually go to 0% CPU usage and just sit there doing nothing until I terminate my program. But if I consume the stdout , then the thread will lock, hurting performance a lot.

I am consuming stderr, it's redirected to stdout.

The only output I need from pngout is the exit value, I'm running it in quiet mode anyway.

e: tested and edited to represent reality

I know you had addressed waitFor before, but I think you need to re-look there. In particular, the first link I give has another link to an old article that shows one solution of how to empty stdout and stderror concurrently and in conjunction with waitFor.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
StreamGobbler works to prevent the threads from locking, yay. Though I only need one since I'm redirecting stderr.
So it looks like this is the proper solution, thanks! Now to go slam my head into a wall until I pass out and never write concurrent code ever again

mustermark
Apr 26, 2009

"Mind" is a tool invented by the universe to see itself; but it can never see all of itself, for much the same reason that you can't see your own back (without mirrors).
I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");?

ComptimusPrime
Jan 23, 2006
Computer Transformer

mustermark posted:

I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");?

If you are already familiar with SQL then start at the official tutorial.

http://download.oracle.com/javase/tutorial/jdbc/

JDBC is (can be) very easy to use as long as you already have a decent understanding of DBMS.

ivantod
Mar 27, 2010

Mahalo, fuckers.

mustermark posted:

I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");?

If you really have to use JDBC here's a hint for you: instead of saying
code:
ps.setXXX(1,...);
ps.setXXX(2,...);
...
ps.setXXX(999,...);
do this:
code:
int i=1;


ps.setXXX(i++,...);
ps.setXXX(i++,...);
...
ps.setXXX(i++,...);
because it's going to be much easier when you inevitably have to add a parameter in the middle for whatever reason.

Is there a reason why you have to use just JDBC? Because there are other options, such as Spring SQLTemplates or even Hibernate/JPA, but it all depends on the size and what kind of project you are working on... As said above, JDBC is pretty easy to use, but kind of low-level. The alternatives are a bit higher level, but may require more effort, especially Hibernate.

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried
Hibernate and Spring JDBC make life so much easier; it's hard to believe how much better they are.

Thom Yorke raps
Nov 2, 2004


Ulio posted:

Thanks Jabor, I am working on it right now.

I wrote an exercise application a few days ago. Which asks the user three ints then shows the user the smallest int, the largest, the product, the average and the sum.

I did make it work but would like to know if there is a shorter way to find out which is the smallest and largest this how I did it.

code:
              if(num1 > num2)
		    if(num1 > num3)
		    if(num2 > num3)
		    {
		    	System.out.printf("Largest is %d\n", num1);
		    	System.out.printf("Smallest is %d\n", num3);
		    }
			if(num1 > num2)
			if(num1 > num3)
			if(num3 > num2)
		    {
			    	System.out.printf("Largest is %d\n", num1);
			    	System.out.printf("Smallest is %d\n", num2);
		    }
			  
I did this for each possibility so it was lots of copying and pasting. I just want to know if there is another way(pretty sure there is), but not something too advanced. Thanks.

How do you find the smallest number in a group of numbers? You go through and look at each number, and remember it if it is smaller than the previous smallest number you have found. So something like:
code:
public void printIntInfo(int... numbers) {
  if(numbers.length < 0) {
    System.out.println("Invalid number of arguments, must be at least one number");
    return;
  }
  int smallest = Integer.MAX_VALUE;
  for(int num : numbers ) {
    if( num < smallest ) 
      smallest = num;
    }
  }
}
Same thing for largest. While you are going through all the numbers, you may as well add them up and calculate the rest of the poo poo you need.

The "int... numbers" part of the argument says this method accepts any number of ints as an argument, including zero. It will also accept an array of ints as a valid argument. If there are no ints, we do some error handling.

epswing
Nov 4, 2003

Soiled Meat

Ranma posted:

if(numbers.length < 0)

I haven't written java in a while, but I'm pretty sure this is wrong.

epswing fucked around with this message at 19:16 on Jul 5, 2011

ComptimusPrime
Jan 23, 2006
Computer Transformer
I believe he really meant == 0 or < 1.

Thom Yorke raps
Nov 2, 2004


ComptimusPrime posted:

I believe he really meant == 0 or < 1.

yeah. That's why we unit test/code review!

TheresaJayne
Jul 1, 2011

mustermark posted:

I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");?

You could move up from JDBC to hibernate, it does run as a standalone, and if you are using 1.5 or higher you can use annotations...

code:
@Entity
@Table (name="users")
public class Users  implements Serializable{
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)	
	@Column(name="user_id")
	private int user_id;
	@Column(name="user_name")
	private String user_name;
	@Column(name="user_password")
	private String user_password;
	@Column(name="user_level")
	private Integer user_level;
and

code:
      public Users getRecordByUsername(String userName) {
		SessionFactory session = HibernateUtil.getSessionFactory();
		Session sess = session.getCurrentSession();
		Transaction tx = sess.beginTransaction();
                Users tempUser = (Users)sess.createQuery("from Users where user_name = ?").setString(0,userName).uniqueResult();
                return tempUser;
        }

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried
I need a good Spring MVC book. Any ideas?

Hidden Under a Hat
May 21, 2003
I have a program that is crashing every 2-3 days, and I can't seem to figure out why. I only have one computer right now available to run the program, a Dell laptop running Windows Vista. I've tried enabling the console in order to see what errors are occurring, but the console does not show up and the Java icon does not appear in the system tray. I have Show Console and Display Java Icon in System Tray selected in the Java control panel, but it still doesn't show up. Has anyone had this issue and been able to resolve it, or does anyone have any other ways to see what errors/exceptions are occurring?

I should go into a bit more detail. I have a thread that is performing various functions in a loop, and this thread is the thing that is locking up. I have other threads that still function when this locks up, so it is not the whole program that is crashing. I tried to cheat a bit by putting all the methods that this thread is executing inside one try-finally block. Basically, at the beginning of the thread loop, I set a boolean variable called threadCompleted to false, and at the end it gets set to true. When the finally block executes, which it does regardless if there was an exception thrown, if threadCompleted = false, then it means it never got set to true and the thread loop never completed. In that case, a new thread is initialized and started in the finally block. This worked in simulated tests, but something is happening in this thread in which even this little cheat isn't working. Anyway, that's why I need to know what error is occurring.

Hidden Under a Hat fucked around with this message at 22:34 on Jul 14, 2011

Paolomania
Apr 26, 2006

Are you able to install a JDK on there? JVisualVM is included in the JDK and pretty useful for coarse profiling. If you cant be around to baby sit it, then get some better logging in there - for instance something in each thread (perhaps a big try inside the run method) that will catch runtime exceptions and make sure they get logged to a file.

Hidden Under a Hat
May 21, 2003
Is there a way to print the stack trace without having a catch statement for a specific exception/error? I have a try-finally block, without a catch statement because I don't know what error/exception is being thrown. That's basically what I want to find out. I would basically like the stacktrace to be printed to a file using printStackTrace in the finally block if the methods contained within the try block do not execute to completion. Or if there is another way to find out the exceptions/errors without knowing which method is the causing it to be thrown.

Adbot
ADBOT LOVES YOU

Blacknose
Jul 28, 2006

Meet frustration face to face
A point of view creates more waves
So lose some sleep and say you tried
You could just catch a generic Exception.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply