Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Java concurrency guidelines.pdf
Скачиваний:
16
Добавлен:
23.05.2015
Размер:
1.35 Mб
Скачать

THI06-J

public static void main(String[] args) throws InterruptedException { DBConnector connector = new DBConnector("suitable query");

Thread thread = new Thread(connector); thread.start();

Thread.sleep(5000);

connector.cancelStatement();

}

}

The Statement.cancel() method cancels the query, provided that the database management system (DBMS) and driver both support cancellation. It is not possible to conform with this guideline if they do not.

According to the Java API, interface Statement documentation [Sun 2009b]

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects.

This compliant solution ensures that only one ResultSet is associated with the Statement belonging to an instance, and, consequently, only one thread can access the query results.

4.7.7Risk Assessment

Failing to provide facilities for thread termination can cause non-responsiveness and denial of service.

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

THI06- J

low

probable

medium

P4

L3

4.7.8References

[Arnold 2006]

Section 14.12.1, “Don't stop”

 

Section 23.3.3, “Shutdown Strategies”

[Darwin 2004]

Section 24.3, “Stopping a Thread”

[Goetz 2006]

Chapter 7, “Cancellation and shutdown”

[Oaks 2004]

Section 2.4, “Two Approaches to Stopping a Thread”

[Sun 2009b]

Class Thread, method stop, interface ExecutorService

[Sun 2008c]

Concurrency Utilities, More information: “Java Thread Primitive Deprecation”

CMU/SEI-2010-TR-015 | 120

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]