This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Abstract Factory + Singleton -> multi-threading ?  RSS feed

 
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether combination of Abstract Factory and Singleton gives multi-threading ?
 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean does it automatically make something thread-safe?
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It always depends on your implementation. Design Patterns are just the clues. The are not strict.
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract factory create the factories and return the sub classes from the factories. If i use singleton with Abstract factory, it controls the object creation.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not clear on what the question is.
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David, Singleton is for creating single instance per JVM. If i use Singleton with Factories will support multi-threading.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't know what you're asking; sorry. Try rephrasing the question.
 
Bartender
Posts: 2292
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

kri shan wrote:Hi David, Singleton is for creating single instance per JVM. If i use Singleton with Factories will support multi-threading.



Oh, I think I see what you mean. It's just that one thing has nothing to do with the other: one thing is multi-threaded programming (multiple Threads), and another one is a factory creating multiple objects. When you have multi-threaded programming, you have concurrency, and you should protect the integrity of the objects that suffer this concurrency (with synchronized methods, synchronized blocks, etc...). A Singleton is an object whose instance is unique, but it can be accessed by one or N Threads.
 
kri shan
Ranch Hand
Posts: 1490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Singleton is an object whose instance is unique, but it can be accessed by one or N Threads using Factories.
Hi Robert, You are correct.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!