When we add logs in to the java class (using log4j), Is it fine to add thread id with that log messages? is it a bad practice? My idea was to add this thread id; Once we examine a log file of a multithreaded application, it is difficult to find out the correct flow using logs. (As an example, say
Create and populate TreeMap in one line
Like an array new Integer[]{ 1, 2, 3 }, can I create and populate a TreeMap using just one line? Any chances for HashMap or LinkedHashMap too? Answer There is no built-in syntax for specifically initializing maps. However, you can take advantage of a special syntax known as “double brace initialization”. The outer pair of braces means that you are
Convert string to List
I have a string with comma separated value that I am getting direclty from database. Now I want to pass that entire string to another query but the datatype required is long and i want to use in clause to get this done. Is there any direct way to do it instead of looping. Answer With guava: EDIT: With a
Hadoop “Unable to load native-hadoop library for your platform” warning
I’m currently configuring hadoop on a server running CentOs. When I run start-dfs.sh or stop-dfs.sh, I get the following error: WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable I’m running Hadoop 2.2.0. Doing a search online brought up this link: http://balanceandbreath.blogspot.ca/2013/01/utilnativecodeloader-unable-to-load.html However, the contents of /native/ directory on hadoop 2.x appear to be
Are server 500 errors a security issue?
I’ve found that it’s possible to cause 500 errors on a server using curl and a faked GWT-Permutation with a POST payload. The payload is generating a java.lang.Exception on an Apache server. Does this open up a security issue? Should I report it to Google’s GWT support? To clarify the question: Would a significant number of server errors be a
Selecting Nth-of-type in selenium
I’m trying to use By.cssSelector to grab the nth dom element with class c3 with a structure like this: Testing my CSS selectors, I’m becoming increasingly confused. This selector selects the 2nd instance of c2/c3 correctly: while: select nothing. Even worse, translating this into selenium, I seem to consistently find nothing for all 3 versions. There are plenty of alternative
Jaas Basic Authentication tomcat 7
I keep on getting the same error, I have already changed the tomcat7w file that specifies the jaas config file location I have already added this tom my tomcat7w.exe file. another is that I also have this realm so what am I missing? please help me, I am using netbeans, tomcat 7.0.47. I have resolved to using glassfish! Answer According
Why is my Spring @Autowired field null?
Note: This is intended to be a canonical answer for a common problem. I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try to use it. The logs show that both the MileageFeeCalculator bean and the MileageRateService bean are being created, but I get a NullPointerException whenever I try
Print Java enum to lower case by default keeping enum constants in uppercase
I have an enum in Java I’d like to serialize, so that when I call it from anywhere in the code, I get the lowercase representation of the name. Let’s say I have the following enum: I’d like to get the following: [Note]: I want to use the enum constants in uppercase, and when requesting the value get the lowercase
java.io.FileNotFoundException: the system cannot find the file specified
I have a file named “word.txt”. It is in the same directory as my java file. But when I try to access it in the following code this file not found error occurs: Here’s my code: Answer Put the word.txt directly as a child of the project root folder and a peer of src Disclaimer: I’d like to explain why