I am using Guava’s LoadingCache into my project to handle thread-{safe,friendly} cache loading and it works wonderfully well. However, there is a limitation. The current code defining the cache looks like this: I don’t specify an expiry time. The problem is that according to the values of the key,…
Tag: java
JDK Locale class handling of ISO language codes for Hebrew (he), Yiddish (yi) and Indonesian (id)
When instantiating a Locale object with either one of the following language codes: he, yi and id it doesn’t preserve their value. For example: What is causing this and is there any way to work around this? Answer The Locale class does not impose any checks on what you feed in it, but it swaps out certa…
Unwanted double quotes in generated CSV file
I have created a CSV file using the Java code below: I am getting the CSV file, but the content of the file has unwanted double quotes. Eg. “ABC”,”123″,”KDNJ” I don’t get from where these double quotes are added. Answer This worked for me See the CSVWriter javadoc
SpringJUnit4ClassRunner class not found
i am trying to create a unit test using SpringJUnit4ClassRunner but everytime i execute the test it says it cannot find SpringJUnit4ClassRunner using mvn install. here is my code Here is my POM file: i am using springSource tool suit IDE to develop this spring mvc app and on the IDE it highlights SpringJUnit4…
Measuring time spent on GC
Suppose I am testing a Java server application. I know how much time it takes to finish the test. Now I’d like to know how much was spent on GC during that test. How can I do it? Answer The simplest way is to use the -Xloggc and -XX:-PrintGCTimeStamps options when starting up your JVM. I think it prints…
Why are reference types stored in heap
I do know that in Java, (perhaps in .net too) , primitives are stored on stacks , where as reference types are stored on heaps. My question was that I do not understand the proc/cons for this behavior. Why can’t we reference a memory location inside our stacks instead? . I couldn’t find a proper e…
JFreeChart with truncated data points
I have created a JFreeChart with the code below, but the Y-Axis marks are truncated. How should I display the chart even though the data points are overlapped in the Y-Axis? Basically, I want the Y-Axis points to be generated from my file, a proper range is populated and displayed in the chart. Below is the i…
How to ensure thread safety of utility static method?
Is there any general way or rules exits by which we can ensure the thread safety of static methods specifically used in various Utility classes of any applications. Here I want to specifically point out the thread safety of Web Applications. It is well know that static methods with Immutable Objects as parame…
Simple (Twitter + Streaming API + Java + OAuth) example
In my quest to create a simple Java program to extract tweets from Twitter’s streaming API, I have modified this (http://cotdp.com/dl/TwitterConsumer.java) code snippet to work with the OAuth method. The result is the below code, which when executed, throws a Connection Refused Exception. I am aware of …
AWS Error Message: A conflicting conditional operation is currently in progress against this resource
I’m getting this error intermittently. I have a program that uses the java aws sdk and loads over the 10s of thousands of small files to s3. I see this error intermittently. Could not find any helpful answer after doing a quick search on the internet. Note the calling program is single threaded. The und…