Refer to Java API
Http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html
Java implements multi-threaded programming in two ways:
One is to inherit the Thread class
class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
The usage is
PrimeThread p = new PrimeThread(143); p.start();
Another method is to implement the runnable interface.
class PrimeRun implements Runnable { long minPrime; PrimeRun(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
The usage is
PrimeRun p = new PrimeRun(143); new Thread(p).start();
On the Android platform, because activity has been integrated, you can only implement the interface.
The thread can be interpreted as a parallel processing program. On the one hand, it is displayed to the user interface and on the other hand, it uploads data to the server.
If you want to upload data at intervals, use
try {Thread.sleep(1000 * 10);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}
This is equivalent to uploading once every 10 seconds.
Today, we solved the logic of how to delete the same data. It took nearly one day.