newCachedThreadPool() versus newFixedThreadPool() When should I use one or the other? Which strategy is better in terms of resource utilization? Answer I think the docs explain the difference and usage of these two functions pretty well: newFixedThreadPool Creates a thread pool that reuses a fixed number of t…
Tag: java
How do I access a config file inside the jar?
I’m using FlatPack to parse and load data from flat files. This requires loading a config file that stores mappings of the columns of the flat file. I have a constant to define the location of the mapping file: I have a parse(File dataFile) method that actually does the parsing: When I jar up everything…
Getting the class name from a static method in Java
How can one get the name of the class from a static method in that class. For example public class MyClass { public static String getClassName() { String name = ????; // what goes here so …
How can I avoid ResultSet is closed exception in Java?
As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it? EDIT: I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue? A…
How to check existence of a program in the path
I’m writing a program in scala which call: I want to check if “svn” is available from the commandline (ie. it is reachable in the PATH). How can I do this ? PS: My program is designed to be run on windows Answer Here’s a Java 8 solution: Replace anyMatch(…) with filter(…).f…
Why does Java have transient fields?
Why does Java have transient fields? Answer The transient keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process. From the Java Language Specification, Java SE 7 Edition, Section 8.3.1.3. transient Fields: Variables may be marked tr…
How to import an existing X.509 certificate and private key in Java keystore to use in SSL?
I have this in an ActiveMQ config: I have a pair of X.509 cert and a key file. How do I import those two in order to use them in SSL and SSL+stomp connectors? All examples I could google always generate the key themselves, but I already have a key. I have tried but this only imports the certificate and
Eclipse open console apps in separate window
Is there a way to configure eclipse to open console apps in a new window rather than it’s own console when you run/debug them? I’m debugging a client/server application and I’d like to see the output of both apps at once and not have to switch between the tabs… Answer In eclipse, you c…
What are Reified Generics? How do they solve Type Erasure problems and why can’t they be added without major changes?
I’ve read Neal Gafter’s blog on the subject and am still unclear on a number of points. Why is it not possible to create implementations of the Collections API that preserve type information given the current state of Java, the JVM and existing collections API? Couldn’t these replace the exi…
Higher-kinded generics in Java
Suppose I have the following class: Now I want to introduce a generic argument, abstracting over the use of Expr: But Eclipse doesn’t like this: The type F is not generic; it cannot be parametrized with arguments <Fix<F>> Is this possible at all or have I overlooked something that causes thi…