Current location - Quotes Website - Personality signature - What is the difference between parallelism and concurrency mechanism in JAVA?
What is the difference between parallelism and concurrency mechanism in JAVA?

What is the difference between parallelism and concurrency mechanism in JAVA?

Concurrency and parallelism are two similar but different concepts: concurrency, also known as *parallelism, It refers to the ability to handle multiple simultaneous activities; parallelism refers to two concurrent events occurring at the same time, which has the meaning of concurrency, while concurrency does not necessarily mean parallelism, which means that concurrent events do not necessarily have to occur at the same time.

----------------------------------------------- ------------------

Is the difference between concurrency and parallelism only the time of occurrence?

Give an example to understand, such as:

Suppose there are two events A and B

Parallel:

If A and B They all happen at the same time at 15:30. The running time of A is 5 minutes and the running time of B is 8 minutes.

The first 5 minutes are parallel, including concurrency, because they all happen at the same time.

Concurrency:

If A occurs at 15:30, event B occurs after 3 minutes of running, and in the next 5 minutes, A and B are concurrent

----------------------------------------------- ---------------

Concurrency means running on the same CPU at the same time (not really at the same time, but it seems to be at the same time, because the CPU needs to run on multiple Switch between programs) to run multiple programs.

Parallel means that each CPU runs one program.

For example, concurrency is like one person (cpu) feeding two children (program), taking turns to feed each person a mouthful. On the surface, both children are eating.

In parallel, two people are feeding two children, and the two children are eating at the same time. The difference between jvm gc parallelism and concurrency

Parallel (Parallel): Multiple garbage collection threads work in parallel, while user threads are still waiting

Concurrent (Concurrent): Garbage collection threads and What is the difference between parallelism and concurrency in Java when user threads work simultaneously (execute alternately) for a period of time?

Parallelism and concurrency have nothing to do with Java, this is an operating system level concept. Concurrency is like one person (CPU) feeding n children (programs), taking turns to feed each child a mouthful. On the surface, both children are eating; parallelism is like n people (CPU) feeding n children (programs). ), n children are also eating at the same time. The difference between sql server and oracle concurrency control mechanisms

1. Openness

1. SQL Server can only run on Windows, there is no openness at all, and the stability of the operating system is It is very important for the database. Windows9X series products focus on desktop applications, and NT server is only suitable for small and medium-sized enterprises. Moreover, the reliability, security and scalability of the Windows platform are very limited. It is not as proven as Unix, especially when dealing with large databases.

2. Oracle can run on all mainstream platforms (including windows). Fully supports all industry standards. Adopt a completely open strategy. This enables customers to choose the most suitable solution. Full support to developers.

2. Scalability and parallelism

1. The parallel implementation and storage model of SQL server are not mature, and it is difficult to handle the increasing number of users and data volumes. Limited scalability.

2. Oracle Parallel Server extends the capabilities of windownt by allowing a group of nodes to share work in the same cluster, providing high availability and high scalability cluster solutions. If windowsNT cannot meet the needs, users can move the database to UNIX. Oracle's parallel server has a high degree of integration with the cluster mechanisms of various UNIX platforms.

3. Performance

1. SQL Server has poor performance when using multiple users

2. Oracle has the highest performance, maintaining TPC-D and TPC under the open platform -C's world record.

4. Client support and application mode

1. SQL Server C/S structure, only supports windows clients, and can be connected using ADO, DAO, OLEDB, and ODBC.

2. Oracle multi-level network computing supports multiple industrial standards and can be connected with network clients such as ODBC, JDBC, and OCI.

5. Easy operation

1. SQL Server is easy to operate, but it only has a graphical interface.

2. Oracle is more complex and provides both GUI and command line. The operation is the same under windowsNT and unix.

6. Risks of use

1. The completely rewritten code of SQL server has gone through long-term testing and continuous delays. Many functions require time to prove. Not very compatible.

2. Oracle’s long-term development experience is fully backward compatible. Be widely used. There is no risk at all. In the final price, ORACLE is more expensive than SQLSRVER. Does PHP have a concurrency mechanism?

Different devices must have independent sessions. The mechanism of session implementation is that the first time the browser visits does not contain any cookies, the server randomly generates a sessionid and returns it to the client as a cookie.

For subsequent visits, the browser will bring this cookie, and the server will treat it as the same session.

It can be seen that if the computer is different, the session must be different.

What is Hibernate's concurrency mechanism?

Hibernate concurrency mechanism:

a. Hibernate's Session object is not thread-safe. For a single request, a single session, A single unit of work (ie, a single transaction, a single thread), which is usually used only once and then discarded.

If a Session instance is allowed to be shared, those that support concurrent operation, such as HTTP requests and session beans, will cause resource contention.

If there is a hibernate Session in the Http Session, synchronous access to the Http Session may occur. As long as the user clicks "refresh" on the browser quickly enough, it will cause two concurrently running threads to use the same Session.

b. Multiple transactions accessing the same resource concurrently may cause a series of problems such as the first type of lost updates, dirty reads, phantom reads, non-repeatable reads, and the second type of lost updates. The difference between python concurrency and java concurrency

The premise of using tornado is that your service is IO-intensive, and you have to write an asynchronous api. You can also refer to the framework in my signature to transform tornado into an eventloop. +threadpool (GitHub - nikoloss/iceworld: multi-thread multi-thread wrapper for tonado). Our company's android ios wap backend is all provided by this framework. It has been switched to a distributed response group. At this time, tornado only exists as a relay gateway: GitHub - nikoloss/cellnest: distributed service

In the absence of blocking, python The performance is definitely not as good as compiled languages. The advantages of this fully asynchronous model cannot be reflected. Once there is an IO operation, the first step of this fully asynchronous model, the apet new connection operation, will not be suspended. That is, as long as content arrives, at least the ioloop link will It can be accepted in full. After receiving, it will be processed by the coroutine. As the concurrency increases, its performance will decrease steadily and smoothly. In contrast, in the threading model, if the consumption of data cannot keep up with the production of new connections and new data, performance will plummet.

Your 700qps is about the same. You can try using Tornado 3.1 or 3.2. 1100~1400 should be able to run out. Of course, whether it is necessary to pursue a static text output performance, I think the actual situation is much more complicated than this simple stress test. The difference between concurrency and parallelism in OS, asynchrony and multi-threading

1. Concurrency: In the operating system, it means that several programs are in a period of time from starting to running to completion, and These programs all run on the same processor, but only one program is running on the processor at any one time.

2. Parallelism: In the operating system, a group of programs are executed at an independent and asynchronous speed. No matter from a micro or macro perspective, the programs are executed together.

3. Multi-threading: Multi-threading is the logical layer concept of programming. It is a piece of code that runs concurrently in the process. Multithreading can realize switching execution between threads.

4. Asynchronous: Asynchronous and synchronous are relative. Synchronization means sequential execution. After executing one, execute the next one, which requires waiting and coordinated operation. Asynchronous means that they are independent of each other and continue to do their own things while waiting for an event. There is no need to wait for the event to complete before working again. Threads are a way to achieve asynchronous. Asynchronous means that the main thread calling the method does not need to wait for the completion of another thread synchronously, so that the main thread can do other things.

5. Asynchronous and multi-threading are not equivalent. Asynchronous is the ultimate goal, and multi-threading is just a means for us to achieve asynchronous.

Asynchronous is when a call request is sent to the callee, and the caller does not have to wait for the return of the result and can do other things. Asynchronous implementation can use multi-threading technology or leave it to another process for processing. What is Hibernate's concurrency mechanism? How to deal with concurrency issues?

a. Hibernate's Session object is not thread-safe. For a single request, a single session, and a single unit of work (ie, a single transaction, a single thread), it is usually used only once and then discarded. If a Session instance is allowed to be shared, those that support concurrent operation, such as HTTP requests and session beans, will cause resource contention. If there is a hibernate Session in the Http Session, synchronous access to the Http Session may occur. As long as the user clicks "refresh" on the browser quickly enough, it will cause two concurrently running threads to use the same Session. b. Multiple transactions accessing the same resource concurrently may cause a series of problems such as the first type of lost updates, dirty reads, phantom reads, non-repeatable reads, and the second type of lost updates. Solution: Set the transaction isolation level. Serializable: serialization. The highest isolation level. Repeatable Read: repeatable read. Read Committed: committed data read. Read Unmitted: uncommitted data read. The worst isolation level is to set locks: optimistic locking and pessimistic locking. Optimistic locking: Use version number or timestamp to detect update loss. Setting optimistic-lock=all in the mapping can implement version checking without version or timestamp attribute mapping. At this time, Hibernate will compare each row of records. Status row-level pessimistic locking of fields: Hibernate always uses the database's locking mechanism and never locks objects in memory! Just specify the isolation level for the JDBC connection and let the database take care of everything.

The class LockMode defines the different locking levels required by Hibernate: LockMode.UPGRADE, LockMode.UPGRADE_NOWAIT, LockMode.READ;