开发者

Java NIO, to use or not to use a framework?

开发者 https://www.devze.com 2023-02-12 19:30 出处:网络
I\'m developing a Java Based server, with NIO multiplex and I started to see a lot of frameworks... I don\'t understand if these frameworks makes the life easier only or has also an increment of per开

I'm developing a Java Based server, with NIO multiplex and I started to see a lot of frameworks... I don't understand if these frameworks makes the life easier only or has also an increment of per开发者_开发知识库formance ( for example netty )


No framework can increase performance of what's underneath it. In the case of NIO I've come around to the view that it already is a framework itself. I've reviewed a couple of NIO frameworks such as Mina, and indeed wrote one myself, but my own conclusion is that this is largely wasted effort, that ultimately gets in the way one way or another. All you need is a well-written select loop and the appropriate data structures.


I think the core point is that they make life easier/get you productive faster. They may be more or less performant compared to each other, or to your own code (no reason to think that if you coded it from scratch you would get better performance the first try - of course ultimately you own it so you can optimize it to death if you want and have the time).

Ultimately they are all using the Java NIO framework and classes, and the only way to outperform those is to do your own JNI - assuming you succeeded - it is hard stuff, really a specialty of its own within programming.


It depends on what you're trying to do. NIO frameworks are useful because they provide you an abstraction of NIO core action. Although, they force you to use several design patterns you may not be comfortable with.

If you think you adapt yourself to those design patterns you should probably use a framework. It will have less bugs, you will have less work to do and ultimately you won't see where all of the action happens. You just have to focus on what you are trying to achieve.

It has some additional overhead in comparison to a "domestic" solution but it is negligible.


It really depends on your level of knowledge with the java.nio API. If you're not sure on how things work then you should probably use a 3rd party API. If you know how things work and are capable of writing code without a 3rd party API then you should definitely use your own code without any strings attached. You can achieve better performance without extra things (3rd party API) going on.

I like to live by the KISS principle.

0

精彩评论

暂无评论...
验证码 换一张
取 消