Skip to content

Instantly share code, notes, and snippets.

- name: install package openJDK 7
apt: pkg=openjdk-7-jdk update_cache=yes
sudo: yes
- name: create archives folder
file: path=/home/vagrant/archives state=directory
- name: Download Tomcat 8
get_url: url="http://apache.crihan.fr/dist/tomcat/tomcat-8/v8.0.0-RC1/bin/apache-tomcat-8.0.0-RC1.tar.gz" dest=/home/vagrant/archives/
- name: Create tomcat directory
file: name=/opt/apache-tomcat owner=vagrant group=vagrant state=directory
sudo: yes
class ThreadProcess implements Runnable {
public int count = 0;
@Override
public void run() {
for (int i = 0; i < 10; i++) {
synchronized (this) {
count++;
}
Thread:t1 Count:1
Thread:t1 Count:2
Thread:t1 Count:3
Thread:t1 Count:4
Thread:t1 Count:5
Thread:t1 Count:6
Thread:t1 Count:7
Thread:t1 Count:8
Thread:t1 Count:9
Thread:t1 Count:10
public class ThreadSharedData {
public static void main(String[] args) throws InterruptedException{
ThreadProcess threads = new ThreadProcess();
// Construct 2 threads
Thread t1 = new Thread(threads, "t1");
Thread t2 = new Thread(threads, "t2");
//Run !
t1.start();
t2.start();
public class ThreadLocalCache
{
private static volatile boolean keepRunning = true;
public static void main( String[] args ) throws InterruptedException
{
(new Thread(){
public void run() {
while (keepRunning){
public class ThreadLocalCache
{
private static boolean keepRunning = true;
public static void main( String[] args ) throws InterruptedException
{
(new Thread(){
public void run() {
while (keepRunning){