- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to synchronize the string type in Java?
A thread is a piece of code (under execution) in a program, which executes a sub task of the process independently. independent process.
In other words, a thread is a light weight process which executes a piece of code independently.
Thread synchronization
If a process has multiple threads running independently at the same time (multi-threading) and if all of them trying to access a same resource an issue occurs.
To resolve this, Java provides synchronized blocks/ synchronized methods. If you define a resource (variable/object/array) inside a synchronized block or a synchronized method, if one thread is using/accessing it, other threads are not allowed to access.
synchronized (Lock1) { System.out.println("Thread 1: Holding lock 1..."); }
Synchronizing Strings
It is not recommended to use objects which are pooled and reused, if you do so there is a chance of getting into deadlock condition down the line.
Since Strings are pooled in String constant pool and reused, it is not suggestable lock String types with Synchronization.
- Related Articles
- Is it possible to instantiate Type-parameter in Java?
- Is it possible to check if a String only contains ASCII in java?
- Is it possible to create a new data type in JavaScript?
- Is it possible to validate the size and type of input=file in HTML5?
- Is it possible to create static constructor in java?
- How to synchronize an ArrayList in Java?
- Is it possible to assign a reference to "this" in java?
- Check if it is possible to transform one string to another in Python
- Is it possible to use this keyword in static context in java?
- How it is possible in MySQL to find a string of specified pattern within another string?
- Is it possible to resume java execution after exception occurs?
- Is it possible to throw exception without using "throws Exception" in java?
- Is it possible to override toString method in an array using Java?
- Is it possible to create a class without a name in Java?
- Is it possible to catch multiple Java exceptions in single catch block?
