我可以通过JNI从Java调用的EPoll C实现

时间:2012-08-29 03:43:22

标签: java c real-time nio epoll

有没有C大师曾在C中实现过Epoll Non-blocking选择器,我可以从Java调用,所以我不必使用Java的NIO Epoll实现?

3 个答案:

答案 0 :(得分:0)

你可以找到我用C编写的epoll示例程序。我希望这会对你有所帮助Could you recommend some guides about Epoll on Linux

答案 1 :(得分:0)

Java 6中的SelectorProvider使用epoll,如果它在内核2.6或更高版本的Linux上运行。

答案 2 :(得分:0)

是的,java支持epoll在JVM源代码中,您可以找到以下代码

JNIEXPORT jint JNICALL
Java_sun_nio_ch_EPoll_epollCreate(JNIEnv *env, jclass c) {
/*  
 * epoll_create expects a size as a hint to the kernel about how to
 * dimension internal structures. We can't predict the size in advance.
 */
int epfd = epoll_create(256);
if (epfd < 0) {
   JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed");
}   
return epfd;
}