How to install JDK 10 on an AWS linux instance

#!/usr/bin/env bash
cd /usr/local/src
wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gz
tar xzf jdk-10.0.2_linux-x64_bin.tar.gz
rm -rf jdk-10.0.2_linux-x64_bin.tar.gz
mv /usr/local/src/jdk-10.0.2 /usr/local/jdkv10
alternatives --install /usr/bin/java java /usr/local/jdkv10/bin/java 2
alternatives --install /usr/bin/jar jar /usr/local/jdkv10/bin/jar 2
alternatives --install /usr/bin/javac javac /usr/local/jdkv10/bin/javac 2
alternatives --set jar /usr/local/jdkv10/bin/jar
alternatives --set javac /usr/local/jdkv10/bin/javac
export JAVA_HOME=/usr/local/jdkv10
export PATH=$PATH:/usr/local/jdkv10/bin
  • Save it as:
install-jdk10.sh
  • Give it execution permission with
chmod +x install-jdk10.sh
  • Run it with sudo:
sudo ./install-jdk10.sh

The @ThreadSafe annotation

When you’re writing a library (or any code, really), you should make sure that you’re not only writing code which will cover your use case for it, but also that you’re doing it in a way that others could benefit from it. With this I don’t mean early optimisations, or functionality which could be easily labeled as YAGNI, let me be clear on that. But effective code should be self-explanatory, not only in the naming and its modularity, but also in the way it can be used. I found a great example of how to do this on the AWS SDK for Java, since I had to use it while trying AWS Lambda. I was trying to determine if I could safely reuse one of their clients when I stumbled upon this comment on StackOverflow about the @ThreadSafe annotation.

Place this annotation on methods that can safely be called from more than one thread concurrently. The method implementer must ensure thread safety using a variety of possible techniques including immutable data, synchronized shared data, or not using any shared data at all.

That’s exactly what I needed, official confirmation from the author of the library (in this case AWS) about its use on a multi-threaded context. It seems that the original idea for this annotation, and others, came in the “de-facto” Java concurrency bible, Java Concurrency in Practice.

AWS have their own implementation of the @ThreadSafe annotation.

/**
 * Documenting annotation to indicate a class is thread-safe and may be shared among multiple threads.
 *
 * @see NotThreadSafe
 */
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface ThreadSafe {
}

And yes, the client I needed is thread-safe.