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.
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.
-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.