Mike Southgate

Ranch Hand
+ Follow
since Jul 18, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Southgate

I need some advice on how to best design something. I have the Java Threads book to cover the thread side, and also the Head First Design Patterns (which I haven't finished yet) to help with the design...

I need to build a gui to start and report on a number of daemons. Each daemon is configurable by about 30 or so properties. Each property can be either a String, boolean, int, TimeStamp etc. The plan is to pass a Collection of DaemonProperties to the Daemon class to tell it how to behave.

What I'm planning thus far...

Create an abstract class called DaemonProperty which will be extended by classes like DaemonPropertyString, DaemonPropertyInt, DaemonPropertyBoolean etc.

I'll then create a DaemonPropertyFactory class which I'll use to actually build the right type of DaemonProperty.

Now the questions...
Obviously the daemon is gonna have to walk the collection of DaemonProperty s and interrogate each to figure out what to do. Trouble is, each property returns a different type so how do I avoid a big switch that has to be changed for each new property I invent?
What is the best form to put the list of properties currently supported in? I'm gonna have to walk this list and pass it into the Factory to get my Collection of DaemonProperty instances.

As an aside, my plan is also to have the DaemonProperty class return a JPanel that contains the components required to interrogate and update the property's value. Any pitfalls you can think of here would be appreciated.

thanks

ms
16 years ago
I'm developing an application that has a large array of shorts. I need to display the values graphically so they can be easily distinguished from each other. I'd like to find a way to create a set of custom glyphs which I could use in an Image. Don't really care if the glyphs are part of a font or not, either would work fine.

Suggestions?

ms
17 years ago
I've implemented dnd from a jlist to a jtable. Now I'd like to be able to drag from one cell in the table and drop into another cell in the same table. My issue is that all of the events (export and import) seem to be triggered as soon as the mouse button is pressed on a table cell, and then nothing happens when the mouse button is released over the new cell.

Does anyone have experience in DND within the same JTable?

ms
18 years ago
Short version of question: how does one ensure that the focusLost processing of a FocusListener is done prior to the component that's gaining the focus changing its state because of the focus?

Long version:
I have a dialog with a JTextArea and a JList. When the user selects an item in the JList, the text area is populated from the JList item's contents. This works fine.
If the user changes the text in the text area, the selected item in the JList needs to be updated. So I've created a FocusListener on the text area with a focusLost method that goes to the JList, determines which item is selected and updates it. This works fine when the component gaining the focus is NOT the JList. When it is the JList, it works about half of the time. The other half of the time the item that's text is updated is the newly selected item, instead of the old one.

Since the documentation says the focusLost event is fired before the focusGained event, I'm assuming that these events are on separate threads. Is this correct, and if so how does one synchronize for this when the method doing the focusGained is not mine?

thanks

mike
18 years ago

Originally posted by Jeanne Boyarsky:
Mike,
A few comments:
1) Try executing the loop with a different prepared statement. For example, try with one that just does a select. This will provide more clues as to the problem.
2) If you are calling this alot of times in production, consider not making it synchronized or executing multiple inserts in a batch.
3) The "ps = null" statement doesn't do anything as the ps variable is about to go out of scope anyway. This isn't the problem, but it's good to know.



Thanks for the input. Re # 3, that is actually left over code from when I thought the issue might be garbage collection and was trying to force earlier cleanup.
I made it synchronized to allow for multi-threading, though that isn't an issue yet.
Batching the inserts is a good idea, that might at least reduce the issue.
I'll also try using selects instead.
One last thing is this used to work OK before I started using the JRE that came with J2EE. I think I'll give 1.5 a shot and see what happens.

ms
I originally posted an eraly version of this question in the java intermediate forum, but investigation indicates its in the jdbc...

I'm getting a java.lang.OutOfMemoryError after calling this method around 4000 times:


As a test I created a loop that went 10000 times and gradually added lines from the above method to see when it blows up. As it turns out, the offending line is : ps.executeUpdate();

I'm using mysql. Any suggestions on how to proceed. Would unloading and reloading the mysql driver help?

Has anyone else out there used mysql with thousands of inserts?

ms
Thanks for the suggestions thus far. I ran a little test and created a loop that tried to save class A in the database 10000 times. It only got to 893 when it ran out of memory too. So I conclude that it's somewhere in my jdbc stuff. Should this be moved to that forum?

Anyway, here is the method being called many times:




It calls some methods in the Position class which is really just a class representing a row of data in a database. The culprits are the methods that do sql so we can focus on the store(count) method, which is listed below:



The DBConnection.getConnection() is a simple connection pooling class I've developed that just grabs existing database connections and then let's you return them to the queue when you're done with them.

ms
19 years ago
Can anyone point me to some decent approaches to isolating where a memory leak is occuring?

I'm reading an XML file (SAX) and storing it in a database. The file contains data for many class A that can contain many class B that can contain many class C. Storing classes A and B in the database seems to work fine, for the entire file. Class C gives a java.lang.OutOfMemory error after handling about 3000 to 4000. I'm not storing them in a collection, just storing them in the database and then re-using the same object to create the next instance.

What's the best way to isolate where this is occurring?

ms
19 years ago
I recently re-installed Eclipse and it's now behaving differently. When running a program and I hit an exception like nullpointer a line shows up in the console window telling me about it. Before, when I clicked on the line it would move me to the offending line of code, now it doesn't. How do I fix this? I've gone through the help and preferences and can't see anything that does this.

ms
What level of user is your book aimed at?

How much does it deal with integration issues with other components?

ms
19 years ago
I'm new to XML so please pardon my open ended questions. I'm using the DOM approach to parse a large XML file (over 15MB) using the following code:


This was working fine for a while, though it did seem to be using a lot of RAM as I had to set the vm heap to 256MB for it to run as I was getting a java.lang.outofMemoryException. I'm now using a different vm and I'm getting this same error even on smaller files that used to work fine.

I'm trying to decide between 2 approaches to resolving this:
1) address the garbage collection to clean up immediately after each top level element has been stored in the database, or
2) switch from the DOM approach to another approach that doesn't parse the entire file first. I'm leaning towards this approach (though I've never used it before and could use some pointers on where to learn about it) as my XML file could get much larger than 15MB.

Which approach would you recommend? If # 2, do you have some suggestions where I could learn this approach quickly (searching on XML yields n! hits...).

ms
My app does not currently support any user help screens. This is something I'll need to implement before too long. What is the best way to implement user friendly help screens? HTML is one option but means either building a lite-browser into my app (don't want to) or using an external browser (don't like that either).

Any suggestions?

ms
19 years ago
It's interesting that while thinking it over at work today I reached the same conclusion. I'll just pass a parameter in to tell the app what db to use and have it use HSQL for the embeded version and MySQL for the server version. That way I can easily add more db's if desired down the line.

I'm planning on using resourceBundle to hold the sql strings for each db.

thanks

ms
19 years ago
First you need to create an actionListener :


then you have to associate it with your button:


ms
19 years ago
Personally, I wouldn't do it that way. I generally create my dialogs and/or panels as completely separate classes. That way you can add as many as you need without bloating your main class. It's pretty easy to pull the inner classes out if you want to.

ms
19 years ago