Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare java and scala in MultiThread aspect [closed]

I just hear and see people saying scala is designed for MultiThread though it's actually for general purpose.

And it claims "The thing is that while you can make classes thread-safe in Java (if you know what you're doing ), Scala makes it easy and natural to do."

And indeed AKKA and Lift is written in scala.(actually java and scala)

But java also did improves in this aspect with the new package of java.util.concurrent. So why didn't AKKA and Lift born in JAVA?

Maybe you will say scala makes java looks like C. :-)

Anyone can tell more insight or deeper thoughts on this?

I know the fact that it is possible to mix JAVA and scala. Scala is able to call seamlessly into Java code. So what java have,so does scala.

But what scala really improves that java haven't done yet regardless of different grammers?

Only some design like Actors/Agents or something else? (note Actors/Agents are cannot solve all the problem in MultiThread.)

Or does scala compiler and adopting some functional language grammer really matters or helps more than in java?

I heard some news that scala is going to be able to adopt XText. To be able to leverage XText to write thread logic, not sure if this is true or not.

Scala looks like a mixture of languages and using this approach makes it more extensible to solve problems in this aspect?

UPDATE

Thanks for your excellent answers from different angles. I think they are all very good. No matter what side you are standing.

EDIT

Topic below (in SO one year ago) was asking about the similiar thing. The "constructive" conclusion is quite similiar. But this time ,some new points are coming out probably the way I am asking is a bit different. Just FYI.

Related:

  • What advantages does Scala have over Java for concurrent programming?

  • Java Concurrency: CAS vs Locking

  • Difference in MultiThread aspect between Java and C/C++

  • Pitfalls/Disadvantages of Functional Programming

Actually I am very interested in some one can answer this question in some brand new angle which could enlighten my mind , provide some idea unknown before.

But it's closed due to not constructiveness. :-)

like image 668
Clark Bao Avatar asked Feb 07 '26 15:02

Clark Bao


1 Answers

I am not really an expert in this, but Scala is a (partly at least) a functional programming language while Java is not (it is imperative). One feature of functional programming is that it avoids (in a 'natural' way) side-effects.

Thread-safety on the other hand is pretty much about avoiding side-effects (i.e. different threads modifying same objects/parts of memory/other resources at the same time).

like image 190
Mchl Avatar answered Feb 09 '26 09:02

Mchl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!