r/java • • Aug 02 '22

Bright future to Java devs ahead 🚀

https://www.youtube.com/watch?v=2nOj8MKHvmw
188 Upvotes

27 comments sorted by

View all comments

-6

u/[deleted] Aug 03 '22

I have been writing a bit more c# than java because of work, so I might be misremembering things, but,

  • At the end of the day internally, cpu has limited threads for all programs, and OS can interrupt one program or one process or one thread to resume another one

  • in java you could always set a fixed number of threads based on the number of cpu threads you want to use

  • in java you could always set a thread pool, and reuse the same threads instead of ending one thread and starting a new one

  • the cpu and OS will not run more threads than it’s designed to run, and will suspend processes or threads as it sees fit to distribute the cpu usage

  • I don’t have all the details of the implementation of green threads, but the general idea, in a specific narrow scope of listening to probably network communication like http, the person developing the web server or web framework doesn’t have to set a thread pool, and can use green threads.

Internally the virtual threads are managed, hopefully in a decent way so it doesn’t interrupt itself too much and takes into account the hardware underneath, the program can say I want a thread to handle this, it will be allowed or temporarily blocked and queued in, then allowed to run, your web api or web application can handle more requests per second or it can handle the same amount of requests per second but can keep more connections open, so throughput might be the same but less connections are dropped if the program can get to them before client timeout or keep alive kick in.

Outside of that one popular thing, is this new scope fork join that different to a developer using the thread class? Pretty sure thread and task in c# has start and join, maybe slight syntax change, maybe it runs faster because creating a thread is a time consuming task.

Personally, I don’t like visual studio compared to IntelliJ idea, but I do like that in c# I can just do await when I need a client to wait for something.

I don’t make web application frameworks, I make client applications and rest apis, and to me I don’t feel the need of having more threads than cpu threads or more threads than 1k, because I would definitely queue things in, if you make too many http or i/o requests they can fail each other or just slow each other out, so there is no real benefit there to me at least.

Now if syntax start changing, it might be good or bad, could be good, if the try block with structured scope task thing blocks the calling thread, and you call getData() without the need to write in every function above it async, that’s good.

Is it better in speed than creating a new virtual thread sure, do client applications care, no, you are about to make a network call with unknown latency and execution time.

Is the scope object good at handling 100 or 1000 requests? If yes then maybe it can be useful but would I wouldn’t want to ddos the api I am calling so I would probably queue things in, so it’s only using 4 or 10 connections.

3

u/plumarr Aug 03 '22

I don’t make web application frameworks, I make client applications and rest apis, and to me I don’t feel the need of having more threads than cpu threads or more threads than 1k, because I would definitely queue things in, if you make too many http or i/o requests they can fail each other or just slow each other out, so there is no real benefit there to me at least.

That's the hole point of virtual thread. You don't have to queue anything. You have an I/O bound operation to make ? Just spawn a thread.

-4

u/[deleted] Aug 03 '22

That’s fine when I need to do a couple of things, but I don’t want to thrash I/o, DB, or someone else’s API.

3

u/kiteboarderni Aug 04 '22

I think you need to read the jep for this. You are misunderstanding the concept entirely.

0

u/[deleted] Aug 04 '22

Dude, the cheeple here, in the the Jeb it will mention the rate limit and ddos and thrashing you will cause to the services you are interacting with?

When you use another entities API, you are going to do thousands of requests per second, and possibly bring their system down or ban your account?

Toxic community has to downvote anything questioning anything. Good job guys, I am logging off of Reddit, enjoy the blind doctrine