• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Sychronization?

 
Shekar Chandu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronization means execution at same time

So Thread Synchronization means execution of multiple threads at same time?

Because of THhread Synchronization  we wil have data inconsistency when multiple threads act on
same data

So Java came up with synchronized keyword

which applied on a method ,it becomes protected from multiple threads.

So Thread synchronization is a concept or Problem?

is Synchronized keyword solution to THread Synchronization?

Is my uderstanding correct?
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shekar Chandu wrote:Synchronization means execution at same time

So Thread Synchronization means execution of multiple threads at same time?


I would be really careful with this definition. Threading is not specific to Java. Threading is not specific to Linux, Solaris, Windows, or whatever OS you are using. And threading is not specific to what processor your are using.

So, there are lots of definitions for threading terms -- and from many contexts. I would really recommend that you use the ones that makes sense in its context.

If you just want to refer to "multiple threads at same time", then "concurrency", "parallelism", and even "time-slicing" may work.... but ... I would still be careful to not use the term out of context.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shekar Chandu wrote:
Because of THhread Synchronization  we wil have data inconsistency when multiple threads act on
same data


Again be careful here. Concurrent threads acting on the same data, *may* have inconsistent data. Or it may not, and it could just work fine.... Or ... it may have inconsistent data, and still work fine. It really depends on the data and what the concurrent threads are doing with it.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shekar Chandu wrote:
So Java came up with synchronized keyword

which applied on a method ,it becomes protected from multiple threads.


Well, in the world of threading, the issue of data inconsistency (that causes problems) is a universal issue. And the various different threading environments come up with different tools, that when applied correctly, solves this data inconsistency/corruption issue.

Of those tools, many of them are similar -- such as Mutex locks, Semaphores, Reader-Writer locks, Condition Variables, CAS operations, etc.  Java (at least starting with Java 5) is one of those environments that provides you access to *all* of the tools listed...

Anyway, with Java, the synchronized keyword, enables the concept of a Mutex lock. The locks are mutually exclusive. Only one thread may own the lock at any one time. So, if you apply them correctly to methods, only one method (of the methods using the same mutex) may be called at any one time. And ideally, if applied correctly, this will lead to not having corrupted data.

Henry
 
Shekar Chandu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Henry

Thanks

so what/ how we can defne Thread Synchronization?

I was confused because of term "Synchronization",which according to dictionary meaning says at same time.

So Thread Synchronization means what in context of "occurs at same time":::::Execution of multiple threads on a sharedobject object one after another?
 
Shekar Chandu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThreadSynchronization

Means different actions of a thread on a shared data should be atomic and should be happen at same time but not at diffeent times

this is only possible by allowing one thread to execute on shared data

that is possible in java using monitors mutex

Here synchronization in thread syncroization means actions of a thread on shared data must happen at a time not at different times if we donot lock the shared data mltple threads might perform their actions on shared data and hence first threads actions will not happen at same time and bcz of ths datainconsistency

Is this correct?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic