Hacker News new | ask | show | jobs
by smegel 4709 days ago
> Wrong. Whether JVM implementations use green threads or system threads is an implementation detail. There are implementations for both cases.

Obviously it is an implementation detail, and for any JVMs that support green threads (none of the major ones do), then it would be a different matter entirely.

> You realize that many JVM implementations started with green threads in the early days and abandoned them not much later? There is a reason for that.

Java was created in the mid-90s before every man and his dog was trying to solve the c10k problem on a $5/month VPS. Hardly surprising.

> Wrong. I repeat, the underlying threading model does not necessarily enforce some style of API.

But it does allow for it, or make it easy. Why do you think Scala has both blocking, and "event based" (loop/react) API's?

> Since when are green threads the “new best thing ever!!!11!!”? Did I miss a memo here?

Quite possibly, you must have been living under a rock if you haven't heard of callback hell in Node.js. Funny because Node was the coolest thing ever a couple of years back, how times change.

> You know what? Wake me up when Go has fixed their broken scheduler. Until then, I just keep watching how the JVM embarrasses Go on pretty much every concurrency and scalability workload.

Java has great MT concurrency. It's light-weight concurrency (NIO) is about as good or bad as any other event-based systems out there. What is lacks (my original comment) is the ability to write event-based code using a synchronous, blocking style (without callbacks).

The only contenders there are Go, Haskell, and possibly some of the scripting language extensions (Python/Gevent, Perl/Coro).

And if by "broken scheduler" you mean it's lack of preemption...then I would say rethink your design, you should be handing long-running jobs to a work queue anyhow.

2 comments

If solutions with manual scheduling like Python's greenlet are acceptable, Lua and basically any LISP should also fit the bill.
> [...] then it would be a different matter entirely

Have fun moving the goal posts around.

> Java was created in the mid-90s before every man and his dog was trying to solve the c10k problem on a $5/month VPS. Hardly surprising.

So what? C10k isn't a hard thing to do on the JVM and it probably beats Go by a large margin in terms of latency and performance.

> Why do you think Scala has both blocking, and "event based" (loop/react) API's?

Your point is ...? There are plenty of different libraries, because concurrency can be tackled in different ways. Use the right tool for the job. Unlike in Go, where you pretty much have to shoe-horn everything into “goroutines” or channels.

The lack of developers which run around and try to tell everyone that they found the silver bullet for solving concurrency in Scala is a sign of a mature community which has experience and expertise and doesn't just repeat whatever Rob Pike says like Go users seem to do all day long.

> Quite possibly, you must have been living under a rock if you haven't heard of callback hell in Node.js.

Eh ... so what? It's not like Node's terrible approach is the only alternative to Go's approach. Claiming “A is the best, because B is even worse” just shows a complete lack of knowledge of existing solutions.

> What is lacks (my original comment) is the ability to write event-based code using a synchronous, blocking style (without callbacks).

Again: No it doesn't. Do your research instead of claiming blatantly false things.

> So what? C10k isn't a hard thing to do on the JVM

It is using the traditional threading model, which is all it had before NIO came along.

> Your point is ...?

My point is if Scala's synchronous API was compatible/built on an event based system or green threads, then the far less attractive callback based API would not exist. Just like Go doesn't have callbacks...what would be the point?

> Use the right tool for the job.

Go doesn't claim to be good at everything. If you want great traditional multi-threading then by all means use Java. If you want a highly-scalable network engine with code that doesn't look like spaghetti, use Go.

> The lack of developers which run around and try to tell everyone that they found the silver bullet for solving concurrency in Scala is a sign of a mature community

I don't don't hear many Java programmers running around complaining about hand-editing reams of XML either...I still don't envy them.

> Claiming “A is the best, because B is even worse” just shows a complete lack of knowledge of existing solutions.

I don't think Go is "best", and I already gave you examples of other synchronous, event-based languages (you still haven't shown me an example in Java/Scala). I actually prefer Python/Gevent for most things.

> Do your research instead of claiming blatantly false things.

Well I think the onus is on you to provide some evidence to back up your claims.

I found the continuations, and they are actually pretty nice.

https://news.ycombinator.com/item?id=6125567

http://jim-mcbeath.blogspot.com/2010/08/delimited-continuati...

https://github.com/jimmc/scoroutine - some of the examples in this are godawful, but you'll find that they still work if you rewrite them to be legible.

  // Some example methods which might spend waiting for other
  // services (calling the database, sending emails).

  def getEMailForUsername(username: String) =
    future { DB.Users.find(_.name == username).get.email }

  def sendPassordRecoveryMail(email: EMail, message: String) =
    future { SMTPService.send(email, message) }

  // Future/Promises API:
  def resetPassword(username: String) =
    for {
      email <- getEMailForUsername(username)
      result <- sendPassordRecoveryMail(email, "some message")
    } yield result


  // Async API:
  def resetPassword(username: String) =
    async {
      val email = getEMailForUsername(username)
      val result = sendPassordRecoveryMail(email, "some message")
      await(result)
    }
@smegel: I don't see any “callback hell” or “code that does look like spaghetti” here. By the way, I'd love to see a link to “Scala's synchronous API” and that mystical “far less attractive callback based API”. Or are you making things up again?