mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
static thread variable
This commit is contained in:
parent
ce4ab7866c
commit
2cd9a2100a
1 changed files with 13 additions and 8 deletions
|
@ -34,7 +34,7 @@ import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
|
||||||
|
|
||||||
public class SynchroniserService extends Service implements IBookCollection.Listener, Runnable {
|
public class SynchroniserService extends Service implements IBookCollection.Listener, Runnable {
|
||||||
private final BookCollectionShadow myCollection = new BookCollectionShadow();
|
private final BookCollectionShadow myCollection = new BookCollectionShadow();
|
||||||
private volatile Thread mySynchronizationThread;
|
private static volatile Thread ourSynchronizationThread;
|
||||||
|
|
||||||
private final List<Book> myQueue = Collections.synchronizedList(new LinkedList<Book>());
|
private final List<Book> myQueue = Collections.synchronizedList(new LinkedList<Book>());
|
||||||
private final Set<Book> myProcessed = new HashSet<Book>();
|
private final Set<Book> myProcessed = new HashSet<Book>();
|
||||||
|
@ -55,10 +55,15 @@ public class SynchroniserService extends Service implements IBookCollection.List
|
||||||
public synchronized void run() {
|
public synchronized void run() {
|
||||||
System.err.println("SYNCHRONIZER BINDED TO LIBRARY");
|
System.err.println("SYNCHRONIZER BINDED TO LIBRARY");
|
||||||
myCollection.addListener(this);
|
myCollection.addListener(this);
|
||||||
if (mySynchronizationThread == null) {
|
if (ourSynchronizationThread == null) {
|
||||||
mySynchronizationThread = new Thread() {
|
ourSynchronizationThread = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
System.err.println("HELLO THREAD");
|
System.err.println("HELLO THREAD");
|
||||||
|
try {
|
||||||
|
ourSynchronizationThread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
System.err.println("START SYNCRONIZING");
|
||||||
for (BookQuery q = new BookQuery(new Filter.Empty(), 20);; q = q.next()) {
|
for (BookQuery q = new BookQuery(new Filter.Empty(), 20);; q = q.next()) {
|
||||||
final List<Book> books = myCollection.books(q);
|
final List<Book> books = myCollection.books(q);
|
||||||
if (books.isEmpty()) {
|
if (books.isEmpty()) {
|
||||||
|
@ -78,11 +83,11 @@ public class SynchroniserService extends Service implements IBookCollection.List
|
||||||
uploadBookToServer(book);
|
uploadBookToServer(book);
|
||||||
}
|
}
|
||||||
System.err.println("BYE-BYE THREAD");
|
System.err.println("BYE-BYE THREAD");
|
||||||
mySynchronizationThread = null;
|
ourSynchronizationThread = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mySynchronizationThread.setPriority(Thread.MIN_PRIORITY);
|
ourSynchronizationThread.setPriority(Thread.MIN_PRIORITY);
|
||||||
mySynchronizationThread.start();
|
ourSynchronizationThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +102,10 @@ public class SynchroniserService extends Service implements IBookCollection.List
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class Request extends ZLNetworkRequest {
|
private static abstract class Request extends ZLNetworkRequest {
|
||||||
private final static String BASE_URL = "https://books.fbreader.org/app/";
|
private final static String BASE_URL = "https://demo.fbreader.org/app/";
|
||||||
|
|
||||||
Request(String app, Object data) {
|
Request(String app, Object data) {
|
||||||
super(BASE_URL + app, toJSON(data), true);
|
super(BASE_URL + app, toJSON(data), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue