How to do wait and notify with two independent threads?
<p>I have created two independent threads using ExecutorService. Now I just want that one thread will write data into a file and another thread will read it after getting notification from the thread which is writing data into a file, but the output is not showing anything, so how can I achieve my goal.</p>

<pre><code>My code is:
package threadingexamples;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadingExamples {

public static void main(String[] args) throws InterruptedException {
    ExecutorService es = Executors.newFixedThreadPool(2);
    es.submit(new ForLoo1());
    es.submit(new ForLoop2());

    es.shutdown();
    es.awaitTermination(1, TimeUnit.DAYS);

    System.exit(0);
}

}

class ForLoo1 implements Callable&lt;Object&gt; {

@Override
public Object call() throws Exception {

    System.out.println("I am writing content into file....");

    String s = "This is the content to write into a file";

    File file = new File("/home/f.txt");

    if (!file.exists()) {
        file.createNewFile();
    }

    FileWriter fw = new FileWriter(file);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(s);
    bw.close();
    System.out.println("Now you can read content from files...");
    notify();
    return null;
}

}

class ForLoop2 implements Callable&lt;Object&gt; {

    @Override
    public Object call() throws Exception {

        wait();
        System.out.println("Okay i am now going to read content of   files...");

        BufferedReader br = new BufferedReader(new FileReader("f.txt"));
        String str;
        while ((str = br.readLine()) != null) {
            str = str + "";
        }
        System.out.println("I am done with reading.....");
        System.out.println(str);
        return null;
    }

}
</code></pre>