I have a question about multi-thread synchronization.

Asked 2 years ago, Updated 2 years ago, 30 views

I'm studying TCP/IP and creating a chat program in Java Among the examples, I saw a data structure class called Vector, and when I investigated Vector, it said that it guarantees synchronization in a multi-threaded environment.

I understand that synchronization is to prevent one resource from being used at the same time.

For example, when clients deliver a message to a TCP server, the TCP server must store the data called the message and send it back to the clients I understand now that I will only synchronize when I receive a message at the same time

Besides Vector, I looked for classes that are synchronized in multi-thread HashTable and String Buffer are also guaranteed to synchronize

What I'm curious about is how Vector, HashTable, and String Buffer are synchronized.

java

2022-09-22 20:19

1 Answers

That's a good question. In multi-threaded, synchronization is a very important concept and is also a difficult part to handle correctly.

Fortunately, Java is more convenient to handle than other environments because the synchronized classification is supported grammatically.

In other words, Vector and Hashtable are synchronized internally, so synchronized processing is possible.

However, synchronization means serial processing, resulting in performance degradation;


2022-09-22 20:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.