“
Accessing shared, mutable data requires using synchronization; one way to avoid this requirement is to not share. If data is only accessed from a single thread, no synchronization is needed. This technique, thread confinement, is one of the simplest ways to achieve thread safety. When an object is confined to a thread, such usage is automatically thread-safe even if the confined object itself is not.
”
”
Brian Goetz (Java Concurrency in Practice)
“
A functional interface in Java 8 is an interface with a single, abstract method. As such, it can be the target for a lambda expression or method reference.
”
”
Ken Kousen (Modern Java Recipes: Simple Solutions to Difficult Problems in Java 8 and 9)
“
Sometimes, you can reduce the latency to an acceptable amount by implementing a batch API for fetching multiple objects in a single round trip. But in other situations, the solution is to combine services, replacing expensive IPC with language-level method or function calls.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
a disciplined team can slow down the pace of its descent toward monolithic hell. Team members can work hard to maintain the modularity of their application. They can write comprehensive automated tests. On the other hand, they can’t avoid the issues of a large team working on a single monolithic application. Nor can they solve the problem of an increasingly obsolete technology stack. The best a team can do is delay the inevitable.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
Simple to develop—IDEs and other developer tools are focused on building a single application. Easy to make radical changes to the application—You can change the code and the database schema, build, and deploy. Straightforward to test—The developers wrote end-to-end tests that launched the application, invoked the REST API, and tested the UI with Selenium. Straightforward to deploy—All a developer had to do was copy the WAR file to a server that had Tomcat installed. Easy to scale—FTGO ran multiple instances of the application behind a load balancer.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
This is the fly in the ointment of free-market capitalism. It cannot ensure that profits are gained in a fair way, or distributed in a fair manner. On the contrary, the craving to increase profits and production blinds people to anything that might stand in the way. When growth becomes a supreme good, unrestricted by any other ethical considerations, it can easily lead to catastrophe. Some religions, such as Christianity and Nazism, have killed millions out of burning hatred. Capitalism has killed millions out of cold indifference coupled with greed. The Atlantic slave trade did not stem from racist hatred towards Africans. The individuals who bought the shares, the brokers who sold them, and the managers of the slave-trade companies rarely thought about the Africans. Nor did the owners of the sugar plantations. Many owners lived far from their plantations, and the only information they demanded were neat ledgers of profits and losses. It is important to remember that the Atlantic slave trade was not a single aberration in an otherwise spotless record. The Great Bengal Famine, discussed in the previous chapter, was caused by a similar dynamic – the British East India Company cared more about its profits than about the lives of 10 million Bengalis. VOC’s military campaigns in Indonesia were financed by upstanding Dutch burghers who loved their children, gave to charity, and enjoyed good music and fine art, but had no regard for the suffering of the inhabitants of Java, Sumatra and Malacca. Countless other crimes and misdemeanours accompanied the growth of the modern economy in other parts of the planet.
”
”
Yuval Noah Harari (Sapiens: A Brief History of Humankind)
“
While such translations may be necessary across bounded contexts, teams should strive to avoid the need for variations in names and structures of the same concept within a single bounded context. The intentional use of ubiquitous language helps avoid such scenarios.
”
”
Premanand Chandrasekaran (Domain-Driven Design with Java - A Practitioner's Guide: Create simple, elegant, and valuable software solutions for complex business problems)
“
When properly designed, multithreaded programs can improve throughput by utilizing available processor resources more effectively. Using multiple threads can also help achieve better throughput on singleprocessor systems. If a program is single-threaded, the processor remains idle while it waits for a synchronous I/O operation to complete. In a multithreaded program, another thread can still run while the first thread is waiting for the I/O to complete, allowing the application to still make progress during the blocking I/O. (This is like reading the newspaper while waiting for the water to boil, rather than waiting for the water to boil before starting to read.) 1.2.2.
”
”
Brian Goetz (Java Concurrency in Practice)
“
multithreaded programs are subject to all the performance hazards of single-threaded programs, and to others as well that are introduced by the use of threads. In well designed concurrent applications the use of threads is a net performance gain, but threads nevertheless carry some degree of runtime overhead. Context switches—when the scheduler suspends the active thread temporarily so another thread can run—are more frequent in applications with many threads, and have significant costs: saving and restoring execution context, loss of locality, and CPU time spent scheduling threads instead of running them. When threads share data, they must use synchronization mechanisms that can inhibit compiler optimizations, flush or invalidate memory caches, and create synchronization traffic on the shared memory bus. All these factors introduce additional performance costs;
”
”
Brian Goetz (Java Concurrency in Practice)
“
Features of Cassandra In order to keep this chapter short, the following bullet list covers the great features provided by Cassandra: Written in Java and hence providing native Java support Blend of Google BigTable and Amazon Dynamo Flexible schemaless column-family data model Support for structured and unstructured data Decentralized, distributed peer-to-peer architecture Multi-data center and rack-aware data replication Location transparent Cloud enabled Fault-tolerant with no single point of failure An automatic and transparent failover Elastic, massively, and linearly scalable Online node addition or removal High Performance Built-in data compression Built-in caching layer Write-optimized Tunable consistency providing choices from very strong consistency to different levels of eventual consistency Provision of Cassandra Query Language (CQL), a SQL-like language imitating INSERT, UPDATE, DELETE, SELECT syntax of SQL Open source and community-driven
”
”
C.Y. Kan (Cassandra Data Modeling and Analysis)
“
Example 6-11. Java Example of Enforcing a Singleton with a Private Constructor public class MaxId { // constructors and destructors private MaxId() { <-- 1 ... } ... // public routines public static MaxId GetInstance() { <-- 2 return m_instance; } ... // private members private static final MaxId m_instance = new MaxId(); <-- 3 ... } (1)Here is the private constructor. (2)Here is the public routine that provides access to the single instance. (3)Here is the single instance.
”
”
Steve McConnell (Code Complete)
“
Accessing shared, mutable data requires using synchronization; one way to avoid this requirement is to not share. If data is only accessed from a single thread, no synchronization is needed. This technique, thread confinement, is one of the simplest ways to achieve thread safety. When an object is confined to a thread, such usage is automatically thread-safe even if the confined object itself is not
”
”
Brian Goetz (Java Concurrency in Practice)
“
common application of thread confinement is the use of pooled JDBC (Java Database Connectivity) Connection objects. The JDBC specification does not require that Connection objects be thread-safe.[9] In typical server applications, a thread acquires a connection from the pool, uses it for processing a single request, and returns it. Since most requests, such as servlet requests or EJB (Enterprise JavaBeans) calls, are processed synchronously by a single thread, and the pool will not dispense the same connection to another thread until it has been returned, this pattern of connection management implicitly confines the Connection to that thread for the duration of the request. [9]
”
”
Brian Goetz (Java Concurrency in Practice)
“
A special case of thread confinement applies to volatile variables. It is safe to perform read-modify-write operations on shared volatile variables as long as you ensure that the volatile variable is only written from a single thread. In this case, you are confining the modification to a single thread to prevent race conditions, and the visibility guarantees for volatile variables ensure that other threads see the most up-to-date value. Because
”
”
Brian Goetz (Java Concurrency in Practice)
“
You can use volatile variables only when all the following criteria are met: Writes to the variable do not depend on its current value, or you can ensure that only a single thread ever updates the value; The variable does not participate in invariants with other state variables; and Locking is not required for any other reason while the variable is being accessed.
”
”
Brian Goetz (Java Concurrency in Practice)
“
To preserve state consistency, update related state variables in a single atomic operation.
”
”
Brian Goetz (Java Concurrency in Practice)
“
ThreadLocal, which allows you to associate a per-thread value with a value-holding object. Thread-Local provides get and set accessormethods that maintain a separate copy of the value for each thread that uses it, so a get returns the most recent value passed to set from the currently executing thread. Thread-local variables are often used to prevent sharing in designs based on mutable Singletons or global variables. For example, a single-threaded application might maintain a global database connection that is initialized at startup to avoid having to pass a Connection to every method. Since JDBC connections may not be thread-safe, a multithreaded application that uses a global connection without additional coordination is not thread-safe either. By using a ThreadLocal to store the JDBC connection, as in ConnectionHolder in Listing 3.10, each thread will have its own connection. Listing
”
”
Brian Goetz (Java Concurrency in Practice)
“
If you are porting a single-threaded application to a multithreaded environment, you can preserve thread safety by converting shared global variables into ThreadLocals, if the semantics of the shared globals permits this; an applicationwide cache would not be as useful if it were turned into a number of thread-local caches. ThreadLocal is widely used in implementing application frameworks. For example, J2EE containers associate a transaction context with an executing thread for the duration of an EJB call. This is easily implemented using a static Thread-Local holding the transaction context: when
”
”
Brian Goetz (Java Concurrency in Practice)
“
Livingston: In addition to all your responsibilities, you were also starting the Rails project. How did you manage it? Heinemeier Hansson: When you have to do a project like Basecamp and you only have 10 hours a week, you can't spend your time on things that don't produce anything. So you get extremely aware of tools that aren't necessarily helping your productivity and you go seeking tools that can help. That's how I found Ruby. It was such a nice experience for me and a nice productivity booster. I was coming from PHP. I had also looked at Java and other environments and I wasn't finding anything else that would allow me, as a single programmer, to deliver all this stuff.
”
”
Jessica Livingston (Founders at Work: Stories of Startups' Early Days)
“
Numbers JavaScript has a single number type. Internally, it is represented as 64-bit floating point, the same as Java’s double. Unlike most other programming languages, there is no separate integer type, so 1 and 1.0 are the same value. This is a significant convenience because problems of overflow in short integers are completely avoided, and all you need to know about a number is that it is a number. A large class of numeric type errors is avoided.
”
”
Douglas Crockford (JavaScript: The Good Parts: The Good Parts)
“
A much better goal is to define a well-designed service to be a service capable of being developed by a small team with minimal lead time and with minimal collaboration with other teams. In theory, a team might only be responsible for a single service, so that service is by no means micro.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
The layered architecture is a great example of an architectural style, but it does have some significant drawbacks: Single presentation layer—It doesn’t represent the fact that an application is likely to be invoked by more than just a single system. Single persistence layer—It doesn’t represent the fact that an application is likely to interact with more than just a single database. Defines the business logic layer as depending on the persistence layer—In theory, this dependency prevents you from testing the business logic without the database.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
The layered architecture is a great example of an architectural style, but it does have some significant drawbacks: Single presentation layer—It doesn’t represent the fact that an application is likely to be invoked by more than just a single system. Single persistence layer—It doesn’t represent the fact that an application is likely to interact with more than just a single database. Defines the business logic layer as depending on the persistence layer—In theory, this dependency prevents you from testing the business logic without the database. Also, the layered architecture misrepresents the dependencies in a well-designed application.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
DDD is quite different than the traditional approach to enterprise modeling, which creates a single model for the entire enterprise. In such a model there would be, for example, a single definition of each business entity, such as customer, order, and so on. The problem with this kind of modeling is that getting different parts of an organization to agree on a single model is a monumental task. Also, it means that from the perspective of a given part of the organization, the model is overly complex for their needs. Moreover, the domain model can be confusing because different parts of the organization might use either the same term for different concepts or different terms for the same concept. DDD avoids these problems by defining multiple domain models, each with an explicit scope.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
The DDD concept of subdomains and bounded contexts maps nicely to services within a microservice architecture. Also, the microservice architecture’s concept of autonomous teams owning services is completely aligned with the DDD’s concept of each domain model being owned and developed by a single team. Even better, as I describe later in this section, the concept of a subdomain with its own domain model is a great way to eliminate god classes and thereby make decomposition easier.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
Ideally, a change will only affect a single team and a single service. CCP is the antidote to the distributed monolith anti-pattern.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
Fetching multiple resources in a single request is challenging.
”
”
Chris Richardson (Microservices Patterns: With examples in Java)
“
The framework is also single-threaded, and its model relies on concurrency which is based on an event loop. It operates in a non-blocking mode, which means that the programs are not blocked but allowed to continue with execution. What happens is that it registers the callback, and then allows the program to continue with the process of execution. Due to the ability of the framework to handle concurrent operations effectively without having multiple threads in the state of execution, the applications are always in a position to scale well.
”
”
Ralph Archer (Node.js: Learn one of the most powerful JavaScript frameworks. Web App Development)
“
The singular purpose of this repository is to load a single instance of an aggregate using its identifier. It is important to note that this repository does not support finding aggregate instances using any other means.
”
”
Premanand Chandrasekaran (Domain-Driven Design with Java - A Practitioner's Guide: Create simple, elegant, and valuable software solutions for complex business problems)
“
Deutsch: Absolutely. Yes. Programs built in Python and Java—once you get past a certain fairly small scale—have all the same problems except for storage corruption that you have in C or C++. The essence of the problem is that there is no linguistic mechanism for understanding or stating or controlling or reasoning about patterns of information sharing and information access in the system. Passing a pointer and storing a pointer are localized operations, but their consequences are to implicitly create this graph. I'm not even going to talk about multithreaded applications—even in single-threaded applications you have data that's flowing between different parts of the program. You have references that are being propagated to different parts of the program. And even in the best-designed programs, you have these two or three or four different complex patterns of things that are going on and no way to describe or reason about or characterize large units in a way that actually constrains what happens in the small. People have taken runs at this problem. But I don't think there have been any breakthroughs and I don't think there have been any sort of widely accepted or widely used solutions.
”
”
Peter Seibel (Coders at Work: Reflections on the Craft of Programming)
“
Speaking your mind is not hurtful. At most, it's annoying for the other person. But silently excluding someone from the group with a stare and without a single word, strips them of the right to defend themselves.
”
”
Alfred Birney (De tolk van Java)
“
If you have a hundred engineers writing Java, a single friendly and helpful Java expert willing to answer questions will soon produce a hundred engineers writing better Java code.
”
”
Titus Winters (Software Engineering at Google: Lessons Learned from Programming Over Time)
“
A namespace is just a JavaScript object that we can use to hold the parts of our application.
”
”
Ben Rady (Serverless Single Page Apps: Fast, Scalable, and Available)