Wednesday, April 24, 2013

ThreadLocal

ThreadLocal example on Oracle documentation does not work, I tried to report it but the steps involved are so cumbersome, I have chosen to post the solution here.

Here is the code that works as intended (ignore the wrong indentation).


import java.util.concurrent.atomic.AtomicInteger;


public class Threads implements Runnable {
    private static final AtomicInteger numThreads = new AtomicInteger(0);

    private static final ThreadLocal < Integer > threadIdHolder
        new ThreadLocal < Integer > ();

    public int getCurrentThreadId() {
        return threadIdHolder.get();
    }

    public Threads() {
    threadIdHolder.set(numThreads.getAndIncrement());
    }
@Override
public void run() {
System.out.println(getCurrentThreadId());
}

private static Integer getNumberOfThreads() {
return numThreads.get();
}

public static void main(String[] args) {
for (int i=0; i<4 i="" p="">
(new Thread(new Threads())).run();
}
System.out.println("Number of threads is: "+getNumberOfThreads());
}
}

The trouble with the code posted in Oracle documentation (http://docs.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html) is that it tries to use the initialValue() method to increment the numThreads variable. However it is called only once because it is static. It can be fixed by making it non static. Alternately keep it static and assign the value to threadIdHolder in the constructor like in this code.

Here is the output:
0
1
2
3
Number of threads is: 4

Friday, January 18, 2013

No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String)

 No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String)

This happened when the class was set (which was the popular fix suggested).

In my case extracting the external jars into the jar when exporting the jar helped.

Wednesday, September 26, 2012

Data not activated on new iPhone 5

I had to turn off the phone for a minute and bring it back up for AT&T to recognize the phone after going through the on phone setup.

Tuesday, August 14, 2012

iSuit

Apple Vs. Samsung law suit

Live notes from San Jose courtroom by Forbes:

The beginning (not really, there was a pre-trial)
Jul 31 2012 

Who says the trial has to be inside the court only... This one is out of court law

Aug 03 2012 

Aug 06 2012

Aug 07 2012 

Aug 10 2012 

Aug 13 2012  Apple is done with its presentation, Samsung to follow with it's witnesses.

Aug 14 2012

Aug 16 2012

Aug 17 2012

Aug 21 2012 Closing arguments

Aug 24 2012 Verdict

One upped by Forbes :)

Tuesday, April 3, 2012

Read URL into a string in scala

def read(url:String):String = io.Source.fromURL(url).mkString

var response = read("http://search.twitter.com/search.json?q=never%20buy&rpp=5&include_entities=true&result_type=mixed")

Monday, January 30, 2012

httpservlet cannot be resolved to a type

include servlet-api.jar from the tomcat lib directory.

Thursday, October 13, 2011

Is Google blocking the verification email sent by Apple's iCloud system?

I have tried resending the verification email 6 times with clean up of spam mail and then going through the spam to see if the mail went to spam. I found the iCloud terms and conditions mail in the spam!

Is the verification mail being blocked at mail servers?

Anyone else with same experience?

It looks like the problem is on Apple's end.

From this link on apple support: http://support.apple.com/kb/HE40 I clicked on Manage my ID and logged in with my apple id. It showed a link to verify. The link did not work from both IE and Chrome.

Looks like a problem on their end.

Finally solved it. I had two accounts at apple one with my email adders and another with a simple string. They both had the same email address registered. Apple was not sending verification email until I changed the simple string one to use a different email address.

Symptom of the problem: iCloud verification email did not arrive in my inbox.