This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

Tom Purl

Ranch Hand
+ Follow
since May 24, 2002
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Purl

Thanks a lot Jeanne! Here's what ended up working:

Thanks again!
9 years ago
I'm trying to run a web application that was designed for Jboss on Tomcat, and I'm having trouble with the database connection. Any help you can give me would be greatly appreciated!

After deploying the application, I created a datasource. I then executed the servlet that tests the "health" of the web app, including the database. When I run that servlet, I get an error stating that it can't connect to the database.

Here's the line of code that's failing:

Here's the error message that I get in /var/log/tomcat6/catalina.out:

And here's my data source config within /etc/tomcat6/context.xml

The problem is that I can't determine if the problem is in the code or in the data source configuration, and I don't know how to debug this.

Here's what I do know:

1. The db is running
2. I can query it using the mysql-client.
3. I can telnet to port 3306 on my machine
4. The servlet works perfectly well on Jboss on someone else's machine
5. I have restarted Tomcat multiple times, and the problem hasn't changed.

So here's my questions:

1. Is there a tool I can use to test Tomcat datasources?
2. Which log level do I need to dial up if I want to get more verbose JDBC error messagess?

Thanks in advance!

Tom Purl
9 years ago
It depends on a lot of factors. First, who has to maintain your scripts? If everyone else on your team is competent with bat file scripting, but doesn't understand Groovy, then you're going to be creating code that no one else can maintain.

If the people you work with do understand Java or Groovy, then you have to ask yourself "which language makes me more productive, and which language is easier to maintain ?".

11 years ago
Personally, when it comes to shell interaction, I do as little of that from my Java program as possible. Up to a certain point, it's pretty easy, but things can get really ugly really quickly. For example, will you be reading error codes from your external application? Is it important to capture STDERR? All of these tasks can be difficult to do from a Java program.

So I guess I would say that if you're doing a little bit of shell integration, then do everything from your Java program. Otherwise, you're better off creating a Java program that simply does validation, and then calling that program from a shell script.


Tom Purl

P.S. If you find yourself writing a lot of Java programs that interact with some sort of shell, you may want to consider looking into Groovy. It has *significantly* better shell integration than plain-old-java, and can save you from having to write a Java program *and* a shell script.
11 years ago
The most popular use case for Groovy is probably web development, using the Grails framework. Also, it works very well as a "scripting" language, and a lot of people are using it to write JUnit tests for their Java code.

I would recommend checking out the "Groovy In Action" book if you would like a general overview of the language. Otherwise, Google is your friend.
11 years ago
I have a simple, console-based application that has a command/repsonse interface that uses jline. My code looks like this:

<pre name="code" class="core">import jline.*

ConsoleReader reader = new ConsoleReader();
String response1 = reader.readLine("enter first response").trim();
String response2 = reader.readLine("enter second response").trim();

Pretty easy stuff. The problem is that I would like to be able to send a kill message to my script using the "CTRL+C" key combination. Jline "swallows" this virtual key, and doesn't act on it unless you tell it to do so.

I therefore threw together some test code that does that:

<pre name="code" class="core">ConsoleReader reader = new ConsoleReader();
char ctrlC = reader.readVirtualKey();
if (ctrlC == ConsoleOperations.CTRL_C) { System.exit(1); }

The problem is that I don't know how to "merge" these two code snippets together. Has anyone done something like this before? If so, how did you do it?

Thanks in advance!
11 years ago
Thanks for the link Gregg. commons-cli is actually my cli-parsing library of choice.

I'm not looking for a CLI-parsing library, however. I'm looking to see if there's a framework that ties together the command line and config files into one hashmap in a way that is easy to configure and maintain. I'm basically trying to copy the UserChoices framework from the "Everyday Scripting With Ruby" book.

Thanks again!
11 years ago
Thanks for your suggestions Norm! I really couldn't find anything as slick as UserChoices, so I'm guess I try to write something myself when I have some free time.

Thanks again!

Tom Purl
11 years ago
I just finished reading "Everyday Scripting With Ruby", and there is a example
framework in there that I would *love* to use with Java/Groovy. It's called
UserChoices, and it's a configuration framework that is tailored for
command-line scripts.

Here's basically how you use it. First, you specify your configuration
sources, which can include files and command-line options. Next, you specify
possible properties that can be extracted from those config sources. Finally,
you specify how those choices should be validated and post-processed. In the
book, all of this is done by subclassing abstract classes, but I'm happy using
a framework that involves more or less coding, as long as it gives me the same

Has anyone seen a framework like this for Java? I write a lot of Java
and Groovy scripts, and the thing I like doing the least is
runtime-option parsing. It always involves a ton of brittle, boilerplate
code that is difficult to unit test. I would love to find a way to
simplify this part of my scripts while increasing readability.

I did look at a few frameworks, like the Commons Configuration framework
and a few J2EE-specific frameworks. These don't do much for me,
however, because they don't pull properties from the command line.

Thanks in advance for any help!

Tom Purl

P.S. I purchased "Everyday Scripting With Ruby" based mostly on the
Bunkhouse review. After reading the book, I can say that the review was
excellent, and that the book was well worth my time and money. If
you're a scripter using *any* programming language (including Groovy),
this book is a definite must-have.
11 years ago
When I create a new project, I often start by creating the following folder/file structure:

This is a bit of a pain, and I would like to automate it. It wouldn't be too difficult to write a shell script that can basically do this, but I was wondering if I could save some time by using an existing script that is robust, mature, and tested.

I know that a lot of tools like Eclipse can do something like this for you automatically, but I work on a lot of projects that don't use Eclipse (or some similar IDE).

Any help would be greatly appreciated. Thanks in advance for the help!

Tom Purl
13 years ago
Thanks a ton for your help, Pradeep!
No, the transformation isn't dependent on having all of the data in memory. My program currently transforms one record at a time. It converts the ResultSet records into an object first to do some validation and manipulation.

My problem is that I need to "chunk" my data retrieval from the database. I can't possibly read all of the data at once and store it into a single ResultSet. However, I've never had to do something like this before and I'm looking for some best practices.

Has anyone seen anything like this on a website or in a book?
I have a general question about reading large amounts of data from a database using Java.

Basically, I am trying to convert a very large amount of data from one data base to another. The data formats are somewhat non-standard, so I have to write a program to do the data transformation.

In the past, I have follwed this basic alogrithm when converting data:

1. Read all of the data from the source into RAM (into some sort of data structure).
2. Validate/manipulate data in the data structure.
3. Read each element in the data structure and write it to the new data source.

Step 1 is no longer a feasible option. Unfortunately, I really don't know of any other way of doing this. Could someone please point me in the direction of a resource or give me a decent idea?

Thanks a ton!

Tom Purl
Don't sweat this type of stuff too much. The exam's purpose isn't to give you every possible permutation of an array declaration to see if you have a java compiler built into your brain. The exam is a good test of your array knowledge, but it doesn't do this by using gimmicky questions.
One important thing to remember about garbage collection (gc) is that you as a programmer can never force it to run. There's no way to ensure that at a particular point in your code all of the memory that you can no longer use will be cleaned up. Even if you have the following line of code in your program, gc isn't compelled to run:

Gc may run in this situtation, but the JVM may decide not to for some reason.
16 years ago