Nov 2, 2010

Problems While Syncing IPod Shuffle

I got a brand new Ipod Shuffle for my older brother as a gift . I downloaded and installed ITunes 10[Yes its required!!] and added songs but when I tried to sync the songs to the shuffle it kept giving strange errors.Like :
  • "Cannot be synced. The Required disk cannot be found."
  • "Cannot be synced. The Required file cannot be found."
  • etc..etc..

I really felt bad for my brother , he was so exited to try it out. After doing some Googling around this is what people had suggested to do to solve the issue.

  • Remove any other USB devices connected to your PC and try syncing again.
  • Going to control panel and refreshing the hardware.[control panel>System>Hardware Tab> Device Manager Button>Highlight your computer name>then click Scan for hardware changes button on the toolbar at the top.]

We tried all this but nothing seemed to work. Then out of curiosity I connected the IPod to a different USB port than Wala!, like a charm it synced all the songs. :)

If you have same or similar problem do try this.

Nov 1, 2010

Common Threading Error [SimpleDateFormat/DecimalFormat]

I have come across a common threading mistake related to Threading in JAVA[I did the same mistake too and spent quite a few sleepless nights thinking what is causing this weird behavior ]. This is related to the The java.text.*Format classes, in java these classes for the most part are NOT thread safe. This is stated in the java doc. Under high volume when the shared/static class is run in two different threads at the same time in the same JVM the data from one thread will be transferred to another thread. These issues most likely will not be reproducible due to timing and are extremely hard to debug .

The Issue
While creating formatters to be used in the java application many people declare the formatters as static elements. e.g.:
  • private static final SimpleDateFormat LOG_DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  • private static final DecimalFormat LOG_AMOUNT_FORMAT = new DecimalFormat("###########0.00");


Solution/Fix

The same code that is thread safe can be written like so:
private static final String LOG_AMOUNT_FORMAT = "###########0.00";

then in your method create a new instance locally.
SimpleDateFormat dateFormatter = new SimpleDateFormat(LOG_AMOUNT_FORMAT);
String formattedDate = dateFormatter.format(myDate);


Hope this helps people avoid the horrible nightmares I had with this issue.