I’m trying to debug a horrible exception that is occurring in a SwingWorker thread. If I could name my SwingWorker threads, then I could better interpret the stack traces I am receiving. It doesn’t seem possible to name a SwingWorker thread (is it?). I’m looking for any best practices or …
Java InputReader. Detect if file being read is binary?
I had posted a question in regards to this code. I found that JTextArea does not support the binary type data that is loaded. So my new question is how can I go about detecting the ‘bad’ file and canceling the file I/O and telling the user that they need to select a new file? Answer For those who …
Java long running task Thread interrupt vs cancel flag
I have a long running task, something like: The task can be cancelled (a cancel is requested and checkIfCancelRequested() checks the cancel flag). Generally when I write cancellable loops like this, I use a flag to indicate that a cancel has been requested. But, I know I could also use Thread.interrupt and ch…
What is a natural identifier in Hibernate?
While reading through the Hibernate documentation, I keep seeing references to the concept of a natural identifier. Does this just mean the id an entity has due to the nature of the data it holds? E.g. A user’s name + password + age + something are used as a compound identitifier? Answer In Hibernate, n…
Running out of java heap space- 15 puzzle problem
G’day all, I tried the solution for eight puzzle problem posted here by joel Neely and played around with it and modified it so that can be used to solve for higher grids[Changed the String representation of the grid to two dimensional integer representation and modified the logic accordingly]. However …
Cannot issue data manipulation statements with executeQuery()
In MySQL I have two tables, tableA and tableB. I am trying to execute two queries: But I get the following error: What does this mean? Answer To manipulate data you actually need executeUpdate() rather than executeQuery(). Here’s an extract from the executeUpdate() javadoc which is already an answer at …
Get type of a generic parameter in Java with reflection
Is it possible to get the type of a generic parameter? An example: Answer One construct, I once stumbled upon looked like So there seems to be some reflection-magic around that I unfortunetly don’t fully understand… Sorry.
Why is Java faster when using a JIT vs. compiling to machine code?
I have heard that Java must use a JIT to be fast. This makes perfect sense when comparing to interpretation, but why can’t someone make an ahead-of-time compiler that generates fast Java code? I know about gcj, but I don’t think its output is typically faster than Hotspot for example. Are there th…
Definition of Java’s CMS GC log lines?
Examining a Java runtime with CMS (Concurrent-Mark-Sweep) GC enabled, what is the definition of the CMS space in the logs below? Shall I assume it is the tenured space? I see the following lines of a minor-major-minor GC event In particular the [CMS: 10899K->9379K(12448K), 0.2675281 secs] at the 23.492 eve…
How to handle a static final field initializer that throws checked exception
I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically, it’d look like this: The issue I have here is that the ObjectName constructor may throw various checked exceptions, which I don’t care ab…