Blackberry JAVA DEVELOPMENT ENVIRONMENT - - CRYPTOGRAPHIC SMART CARD DRIVER - DEVELOPMENT GUIDE Průvodce řešením problémů Strana 120

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 286
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 119
120
BlackBerry Java Development Environment Development Guide
* the shared data in a synchronized block, but produces less overhead.
*/
private volatile boolean _start = false;
private volatile boolean _stop = false;
/**
* Retrieve the URL. The synchronized keyword makes sure that only one
* thread at a time can call this method on a ConnectionThread object.
*/
public synchronized String getUrl() {
return _theUrl;
}
/**
* Fetch a page. This method is invoked on the connection thread by
* fetchPage(), which is invoked in the application constructor when
* the user selects the Fetch menu item.
*/
public void fetch(String url) {
_start = true;
_theUrl = url;
}
/**
* Close the thread. Invoked when the application exits.
*/
public void stop() {
_stop = true;
}
/**
* Open an input stream and extract data. Invoked when the thread
* is started.
*/
public void run() {
for(;;) {
// Thread control.
while( !_start && !_stop) {
// No connections are open for fetch requests,
// but the thread has not been stopped.
try {
sleep(TIMEOUT);
} catch (InterruptedException e) {
System.err.println(e.toString());
}
}
// Exit condition.
if ( _stop ) {
return;
}
/* Ensure that fetch requests are not missed
* while received data is processed.
*/
synchronized(this) {
// Open the connection and extract the data.
StreamConnection s = null;
try {
s = (StreamConnection)Connector.open(getUrl());
Zobrazit stránku 119
1 2 ... 115 116 117 118 119 120 121 122 123 124 125 ... 285 286

Komentáře k této Příručce

Žádné komentáře