Log in

Java developers

Recent Entries

8/25/11 02:59 am - ska_o - stack overflow crash

Hi all,

Can anyone suggest a way to dump the stack trace just when the JVM crashes due to stack overflow error?

I know it's possible and I've done it before, but it's been a while. It could have been with a third-party tool like YourKit, or maybe there are some well-hidden JVM options for that? Can't find anything right now.

I could create an error handler that would try to dump the stack trace for every thread; not sure if that would work.

The code that's crashing is not mine and it's pretty complicated, and while the basic reason for this error is pretty obvious, it won't be easy to find without the stack trace. It runs for a few hours before it gets the error, and at least in the beginning the stack looks OK.

Hopefully, there is a simple way to get it at the moment of the crash.

Any ideas will be appreciated.

6/10/11 04:51 pm - banana - Snippet of the day

Just came across this:


Yes, that should make doubly sure it's in upper case.

6/5/11 08:09 pm - ruakh - The ternary operator.

I'm helping a new co-worker, fresh out of college, become familiar with our products. For one of the tasks he's been assigned, I was showing him how I would go about it, and part of my sample code used the ternary (conditional) operator — the b ? e1 : e2 notation. As it turns out, he had never encountered that notation before, and I had to explain it to him. I'm wondering — is that normal? He's a smart guy, and he had no problem understanding the notation once I explained it, but I was surprised that he wasn't already familiar with it.

I know that the ternary operator is sometimes considered bad style, but this case really seemed to be crying out for it — two versions of a large SQL statement, with only one small difference in the middle. This seemed the clearest and most readable way to code it. But if I can't expect people to be familiar with that operator, then I can't expect that code to be clear to them!

What do y'all think? Would you expect the typical Java programmer to be familiar and comfortable with it?

(With normal simple cases, I mean, like (b ? "string_literal_1" : "string_literal_2") and whatnot. Obviously I wouldn't expect people to be comfortable with crazy edge cases, like when autoboxing or implicit widening conversions are involved.)

4/5/11 10:37 am - banana - Spring object pooling woes

Spring's AOP support says that it includes object pooling. If you're using Spring and you have some object that is expensive to create, you can make a pool of some re-usable instances, and the documentation has an example of how to create a pool.

But according to my testing, the pool returns the same instance every time. Oops.

I found an old (2004) blog entry about this problem which included the a suggestion about making it work:
<bean id="businessObject"
  <property name="targetSource" ref="poolTargetSource" />
  <!-- Added the following line -->
  <property name="singleton" value="false" />
This does indeed make the pool return different instances. But it doesn't explain how instances get returned to the pool. I was hoping that some Spring magic would occur to make this happen, but no. What seems to happen is that eventually the pool hands out an instance that has been used before, and it doesn't take many concurrent threads until your app gets into trouble because the same instance is used twice at once. Ouch.

So, Spring object pooling appears broken, unless you know better...

1/12/11 08:17 pm - crazylikefox - Introduction & Questions

Hello :)

I have recently started adventuring into the Java sphere.  I am a n00blet.  I enjoy firearms, belly dancing, and linguistics.  When it comes to the geek arts I am still a novice.  That being said, I am working on learning more, and currently am on hour ten of "Sams Teach Yourself Java in 24 Hours".  It has to do with creating objects.  Hour 9 was very intense with multidimensional arrays.  I still have questions on those.

They say to be a good programmer you have to be good with logic puzzles.  So here is a puzzle I would like help with, if you guys have the time.

Here is the original code from hour 7, which is using conditional tests to make decisions:


What I am trying to do is modify it a little here:

package Java24;
import java.util.Scanner;

class Grade {
    public static void main(String[] args) {
        Scanner langi = new Scanner(System.in);
        int grade = 24242424;
        if (grade > 89)  {
            System.out.println("You got an A. Great job!");
        } else if (grade > 79) {
            System.out.println("You got a B. Good work!");
        } else if (grade > 69) {
            System.out.println("You got a C. You'll never get into a good college!");
        } else if (grade <= 101) {
            System.out.println("You are a fool.");
        } else {
            System.out.println("You got an F. You'll do well in Congress!");

Two things I am trying to do:

1.  I am trying to get the program to ask me what my number grade was instead of putting a number directly into the code with int grade = 24242424.  Haven't been successful yet.

2.  I am trying to have the program output "You are a fool." if you put in a score higher than 100.  Right now it is just seeing that the score is higher than 89 and prints the line and that is the end of it.

Any help would be greatly appreciated!

Thanks :)

10/2/10 09:55 am - mrflash818 - Debian Lenny and Eclipse v3.2 bugfix

Fired up eclipse v3.2 in Debian lenny stable, ...and received error messages! oh no!

"robert@pip:~$ eclipse
searching for compatible vm...
  testing /usr/lib/jvm/java-6-openjdk...not found
  testing /usr/lib/jvm/java-gcj...found
/usr/lib/jvm/java-gcj/bin/java: symbol lookup error: /home/robert/.eclipse/org.eclipse.platform_3.2.0/configuration/org.eclipse.osgi/bundles/149/1/.cp/libswt-mozilla-gtk-3236.so: undefined symbol: _ZN4nsID5ParseEPKc"

Okay, then did a quick google search on the phrase "libswt-mozilla-gtk-3236.so: undefined symbol"

Which led me to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=511713

and eclipse 3.2.2-6.1 should start under lenny."
So I then did robert@pip:~$ sudo aptitude install xulrunner-dev

Now eclipse v3.2 fires up fine in my Debian Lenny stable workstation.

7/26/10 02:52 pm - banana - Incomprehensibility

Today I was trying to run a web app written elsewhere. Everything came pre-built, and Tomcat was included. Should be a piece of cake, eh?
SEVERE: Error filterStart
Googling that found a lot of people with this problem, each with a different resolution.

The real problem is that the error message means nothing. Sadly, this is normal. Everything that requires XML configuration (Tomcat, JBoss, Swing, Struts, etc. etc. etc.) will fail if you don't know all its arcane configuration rules, and give you an error that doesn't tell you what the problem is so you can't fix it.

When your software goes wrong, tell me what the problem is. Don't join the useless, time wasting, exasperating tidal wave of incomprehensible dross.

So, the upshot of this is that I shall never find out if Hammurapi is any use.

5/6/10 11:51 am - banana - Quiz of the day

What is the output?
public class SystemExit{
   public static void main(String... args){
      Runtime.getRuntime().addShutdownHook(new Thread(){
         public void run(){
            System.out.println("Message 2");
         System.out.println("Message 1");

4/27/10 04:24 pm - anna_mryglo - Looking for java/j2ee developer in Kiev


4/10/10 11:38 pm - sophiaserpentia - starting a server and client using ant

What I want to do is to run a JUnit test on a class that uses a socket connection to a server, from within an Ant build.xml. Naturally, to test the client socket, it first has to open a serverSocket that waits for input from a client. What's happening is that Ant opens the serverSocket, and then hangs along with the server waiting for input from a client. It doesn't move on to the next task, which is to run the JUnit test.

I thought perhaps that adding 'fork="true"' should do the trick, since (so I understand) it should start both server and client classes in different instances of the JVM. That isn't working, though.

This seems like it should be a pretty routine thing. It works if I open the server manually and then run the JUnit tests. But not from within Ant.

Thanks in advance for any assistance!
Powered by LiveJournal.com