shared database for multithreading
can someone help me with the trade-offs and pitfalls of creating a shared database?
im building an uber-like project that needs to save a list of drivers and their state -as in free, or occupied in an another ride- across all threads.
can someone guide me? its a console app.
24 Replies
⌛ This post has been reserved for your question.
Hey @HanaBanana! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
wdym by shared database
u mean a db that can be accessed by multiple threads at once
transactions will be helpful
and locking
optimistic or pessimistic depending on the use case
a shared hashmap
how is it shared tho
like threads access it at the same time
or something
yeahhh can write and read from it concurrently
i just learnt about connection pooling
do you have any idea how can i use this in my case?
its gonna create conflicts tho
what if one thread deletes something from the hasmap
while the other tries to update something
for the same drive
r
connection pooling is said to be a solution to this
connection pooling is for
connecting to real databases
not accessing a hashmap
yeahhhh i figured..
what are we doing now 🙁
what exactly do you want
lock the whole hashmap
or only a specific key and value
when one thread is accessing it
good question
can i just explain the use case?
because im unfamiliar with those terms
sorry
Access HashMap by multiple threads concurrently (Threads forum at C...
I have a static HashMap will be shared by multiple threads in a real time applicaiton. Do i need to synchronize list variable inside process method?.
si
Use a
ConcurrentHashMap then.its probably the simplest solution yea
GeeksforGeeks
ConcurrentHashMap in Java - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
Also do you need to persist your data? Do you have multiple processes, possibly on different machines all accessing the same data? Use a database.
Do you just need an in-memory cache? Use a
HashMap.
Does it need to support writes and reads from multiple threads? Use a ConcurrentHashMap.multiple threads
just know that with a concurrent hash map the buckets might lock some other keys when you are updating one specific key
so if you lets say update driver1 theres a chance driver2 and driver3 will be locked for the time of updating driver1
but in your case a concurrent hash map should be fine
yeah i think so too but i will test the usecase once im done coding it cus it will take me time since i dont know these concepts and im trying to avoid using ai
if you wanna finish the app faster id say first do a single threaded version
and then switch to multithreading
its already multithreaded, do u wanna see the repo?
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.test
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.