#Usage of Synchronized

1 messages · Page 1 of 1 (latest)

midnight wolf
#

I'm designing an engine and I'm making some utility methods.

My engine is not supposed to run in parallel, but let's suppose, in the future, that someone just come up with an idea to do this multi-threaded. Should I explicitly mark my methods as synchronized and ensure that this was not designed to run in parallel?

If so, all of my projects should have this keyword then. Should I always use it when I don't want parallelism?

woeful deltaBOT
#

<@&987246841693360200> please have a look, thanks.

woeful deltaBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

old herald
#

Nah

#

It's fine to have classes that aren't safe to share between threads

#

But I will say that if you use records and immutable data it becomes a lot easier later

old herald
#

Why is it fine to do things? Idk

dawn wing
# midnight wolf > I'm designing an engine and I'm making some utility methods. My engine is no...

So first, syncronized is a huge slow down hit, that's why ArrayList was created when Vector already existed, because you don't want your program to be slow forever just because someone might make it parallel at some point.
Also, using syncronized to solve concurrency problems is a myth. You can't just put syncronized everywhere and except that when you make it parallel it will work, not it won't, it's in fact the opposite
If you want to prepare it so it can be easily parallelised, you "simply" have to use correct design, also note that usually good practices will make your program easily parralelizable, like using immutable value, avoiding side effects, one thing per method, etc

midnight wolf
#

I see the point

#

Thx