• Post Reply Bookmark Topic Watch Topic
  • New Topic

object with many threads

 
jacob deiter
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an application developed without considering about multithreading,
for example if thread -1 accessing a object ,if another thread,thread-2 try to access the same object then Tread 2 wait for Tread-1 to finish or it start immediately?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jacob deiter:
If an application developed without considering about multithreading,
for example if thread -1 accessing a object ,if another thread,thread-2 try to access the same object then Tread 2 wait for Tread-1 to finish or it start immediately?


http://java.sun.com/docs/books/tutorial/essential/concurrency/interfere.html
 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless the thread 'accessing' the object is performing an atomic action, without locks (or semaphores..some kind of concurrency control), you cannot be sure that Thread 1 has finished it's work with the object before Thread 2 starts.

It may even be possible that thread 2 gets to the object before thread 1.

Semaphores are a easy way to control multi-threaded access to a resource.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something which would sit better on our threads forum.

Moving.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!