Friday, July 26, 2013

Oracle SOA File Adapter - Spaces in pay load

Recently we got a new integration for reading a file.  We don't know the source of the file, so we started developing with default values, for the File Adapter in JDeveloper.
The given file is a comma-separated with Double quotes as shown below.





However when configuring the JDEV, when the default CHARACTER SET US-ASCII is given to this file, it started inserting spaces between each character inside an element.




Initially we ignored this and developed out component.  But during run time, we were getting the pay load with spaces and are not able to figure out what the real issue is.

Basically this is a file format issue and by Just changing the Character Set to UTF-16 in the File Adapter XSD, this got fixed.

Sunday, July 21, 2013

Java - Interesting..

SimpleDateFormat is not ThreadSafe.  

http://www.codefutures.com/weblog/andygrove/2007/10/simpledateformat-and-thread-safety.html

Also,
SimpleDateFormat stores intermediate results in instance fields. So if one instance is used by two threads they can mess each other's results.
Looking at the source code reveals that there is a Calendar instance field, which is used by operations on DateFormat / SimpleDateFormat
For example parse(..) calls calendar.clear() initially and then calendar.add(..). If another thread invokes parse(..) before the completion of the first invocation, it will clear the calendar, but the other invocation will expect it to be populated with intermediate results of the calculation.
One way to reuse date formats without trading thread-safety is to put them in a ThreadLocal - some libraries do that. That's if you need to use the same format multiple times within one thread. But in case you are using a servlet container (that has a thread pool), remember to clean the thread-local after you finish.
To be honest, I don't understand why they need the instance field, but that's the way it is. You can also use joda-time DateTimeFormat which is threadsafe.
=================================================================================

HASHMAP - MULTITHREAD RACE CONDITION EXPLANATION