Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads on Objects

 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Client is



If client code is inside for loop from 1 to 1000, then if 1000 objects will get unique value???
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what output comes when you try it?
 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Output giving me unique records, but will it be safe in future.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this was answered in a previous topic of yours. No, time is not unique. If the method gets called multiple times within the same clock tick interval, then the output would be the same. This is more likely to happen in a threaded environment but is also able to happen in a single thread if it is run fast enough.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vivek dhiman wrote:


Client is



Why are the clients creating an Object instance to access the static method? This is misleading and shouldn't be done. You should do classname.generateIdforDCR();. But your class name should be better (i.e. be descriptive, start with a capital letter).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic