Category: Result Set Concurrency

Concurrent Collections and Maps 2 – Concurrency: Part II

Some collections allow the null value, and others do not. All concurrent collections, blocking queues, and concurrent maps do not allow the null value as elements, whereas the copy-on-write collections do. All collections that embody the concept of a set do not allow duplicates—for example, a CopyOnWriteArraySet. All maps (e.g., a ConcurrentHashMap) do not allow

Concurrent Collections – Concurrency: Part II

Concurrent Collections Concurrent sets, queues, and deques are implemented by the classes Concurrent-SkipListSet, ConcurrentLinkedQueue, and ConcurrentLinkedDeque, respectively. These thread-safe classes implement the corresponding NavigableSet, Queue, and Deque interfaces in the java.util package, as shown in Figure 23.4 and summarized in Table 23.5. Their characteristics are summarized in Table 23.6. These concurrent collections are unbounded and

The ConcurrentNavigableMap Interface – Concurrency: Part II

The ConcurrentNavigableMap<K,V> Interface A concurrent, sorted map is defined by the ConcurrentNavigableMap<K,V> interface that extends both the ConcurrentMap<K,V> and the NavigableMap<K,V> interfaces. It overrides the methods shown below from its superinterfaces. Details on these overridden methods can be found in the ConcurrentMap<K,V> interface (p. 1491) and in the NavigableMap<K,V> interface (§15.10, p. 845). The ConcurrentSkipListMap<K,V>

The BlockingQueue Interface – Concurrency: Part II

The BlockingQueue<E> Interface The java.util.concurrent.BlockingQueue interface extends the java.util.Queue interface, as shown in Figure 23.6. Compared to the operations shown for the Queue interface in Table 23.7, the BlockingQueue interface provides new insert and remove operations that can block or can time out—shown in the two rightmost columns in Table 23.13. Classes that implement the

Copy-on-Write Collections – Concurrency: Part II

Copy-on-Write Collections The copy-on-write collections comprise special-purpose concurrent lists and sets that are recommended when read operations vastly outnumber mutative operations on the collection. The classes CopyOnWriteArrayList and CopyOnWriteArraySet implement the List and the Set interfaces in the java.util package (Figure 23.7). A summary of the copy-on-write classes in the java.util.concurrent package is given in

The CopyOnWriteArraySet Class – Concurrency: Part II

The CopyOnWriteArraySet<E> Class The CopyOnWriteArraySet class implements the java.util.Set interface (§15.4, p. 804). It does not implement any additional methods. Internally it uses a CopyOnWriteArrayList, and therefore shares the same basic properties with the list, except that, being a set, it does not allow duplicates and its elements have no ordering. Example 23.21 illustrates the

Basic SQL Statements – Database Connectivity

Basic SQL Statements Structured Query Language (SQL) is used to perform relational database operations. Despite the existence of an ANSI (American National Standards Institute) SQL standard, different database providers may provide SQL implementations that are not exactly the same and may contain nuanced differences and proprietary additions. SQL statements can be logically grouped into a

Basic SQL Statements 2 – Database Connectivity

The UPDATE Statement The UPDATE statement can be used to update specific rows in a table. In other words, this statement modifies zero or more rows in the table: Click here to view code image UPDATEtable_name SETcolumn_name_value_pairs WHERErow_filter; where column_name_value_pairs in the SET clause is a comma-delimited list of pairs of column names and values: Click here

Getting a Database Connection – Database Connectivity

Getting a Database Connection To create a connection to a Derby database, the following code can be emulated: Click here to view code image String jdbcURL  = “jdbc:derby:localhost:1521:musicDB”;String username = “joe”;String password = “welcome1”;try (Connection connection = DriverManager.getConnection(jdbcURL,                                                         username, password)) {  /* use the connection. */} catch (SQLException e) {  e.printStackTrace();} A portion of the

SQL Injection – Database Connectivity

SQL Injection Passing the SQL operation as a string in the execute method presents the risk of a SQL injection, as malicious SQL code can be injected into the query string. Assume that there is a basic statement that queries a table, where the query is dependent on a value: Click here to view code