首页 \ 问答 \ 在ubuntu 16.04中不支持java aio SO_KEEPALIVE?(java aio SO_KEEPALIVE not supported in ubuntu 16.04?)

在ubuntu 16.04中不支持java aio SO_KEEPALIVE?(java aio SO_KEEPALIVE not supported in ubuntu 16.04?)

我正在测试java AsynchronousServerSocketChannel,但是当我尝试设置SO_KEEPALIVE = true时,一条错误消息显示我不支持它? 如何解决以下问题? ubunut服务器真的不支持keep-alive吗?

代码是:

private void init(String host, int port) {
    try {
        final AsynchronousChannelGroup group = AsynchronousChannelGroup.withCachedThreadPool(Executors.newCachedThreadPool(), 10);
        final AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel
                .open(group).bind(new InetSocketAddress(host, port))
                .setOption(StandardSocketOptions.SO_KEEPALIVE, true)
                .setOption(StandardSocketOptions.TCP_NODELAY, true)
                .setOption(StandardSocketOptions.SO_REUSEADDR, true)
                .setOption(StandardSocketOptions.SO_RCVBUF, 16 * 1024);
        System.out.println("Listening on: " + host + ":" + port);
        System.out.println("Channel Provider : " + server.provider());
        server.accept(null, new handler());
        group.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        //TimeUnit.DAYS.sleep(Long.MAX_VALUE);
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(AIOEchoServer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

private class handler implements CompletionHandler<AsynchronousSocketChannel, Void> {

    @Override
    public void completed(AsynchronousSocketChannel result, Void attachment) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void failed(Throwable ex, Void attachment) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

错误是:

Exception in thread "main" java.lang.UnsupportedOperationException: 'SO_KEEPALIVE' not supported
at sun.nio.ch.AsynchronousServerSocketChannelImpl.setOption(AsynchronousServerSocketChannelImpl.java:187)
at TestAIO.AIOEchoServer.init(AIOEchoServer.java:28)
at TestAIO.AIOEchoServer.main(AIOEchoServer.java:20)

I am testing java AsynchronousServerSocketChannel, but when I tried set SO_KEEPALIVE=true, a error message showed me that not support it? How to fix below issues? It is really not support keep-alive in ubunut server?

The code is:

private void init(String host, int port) {
    try {
        final AsynchronousChannelGroup group = AsynchronousChannelGroup.withCachedThreadPool(Executors.newCachedThreadPool(), 10);
        final AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel
                .open(group).bind(new InetSocketAddress(host, port))
                .setOption(StandardSocketOptions.SO_KEEPALIVE, true)
                .setOption(StandardSocketOptions.TCP_NODELAY, true)
                .setOption(StandardSocketOptions.SO_REUSEADDR, true)
                .setOption(StandardSocketOptions.SO_RCVBUF, 16 * 1024);
        System.out.println("Listening on: " + host + ":" + port);
        System.out.println("Channel Provider : " + server.provider());
        server.accept(null, new handler());
        group.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        //TimeUnit.DAYS.sleep(Long.MAX_VALUE);
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(AIOEchoServer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

private class handler implements CompletionHandler<AsynchronousSocketChannel, Void> {

    @Override
    public void completed(AsynchronousSocketChannel result, Void attachment) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void failed(Throwable ex, Void attachment) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

The error is:

Exception in thread "main" java.lang.UnsupportedOperationException: 'SO_KEEPALIVE' not supported
at sun.nio.ch.AsynchronousServerSocketChannelImpl.setOption(AsynchronousServerSocketChannelImpl.java:187)
at TestAIO.AIOEchoServer.init(AIOEchoServer.java:28)
at TestAIO.AIOEchoServer.main(AIOEchoServer.java:20)

原文:https://stackoverflow.com/questions/38028550
更新时间:2023-05-23 17:05

最满意答案

不, SELECT ... FOR UPDATE不会阻止插入。

DML操作中的自动锁定

行独占锁(RX),也称为子独占表锁(SX),表示持有锁的事务已更新表行或发出SELECT ... FOR UPDATE。 SX锁允许其他事务在同一个表中同时查询,插入,更新,删除或锁定行。 因此,SX锁允许多个事务为同一个表获取同时的SX和SS锁。


No, SELECT ... FOR UPDATE won't prevent inserts.

Automatic Locks in DML Operations:

A row exclusive lock (RX), also called a subexclusive table lock (SX), indicates that the transaction holding the lock has updated table rows or issued SELECT ... FOR UPDATE. An SX lock allows other transactions to query, insert, update, delete, or lock rows concurrently in the same table. Therefore, SX locks allow multiple transactions to obtain simultaneous SX and SS locks for the same table.

相关问答

更多
  • 不, SELECT ... FOR UPDATE不会阻止插入。 DML操作中的自动锁定 : 行独占锁(RX),也称为子独占表锁(SX),表示持有锁的事务已更新表行或发出SELECT ... FOR UPDATE。 SX锁允许其他事务在同一个表中同时查询,插入,更新,删除或锁定行。 因此,SX锁允许多个事务为同一个表获取同时的SX和SS锁。 No, SELECT ... FOR UPDATE won't prevent inserts. Automatic Locks in DML Operations: A ...
  • 需要更多信息...如果您正在谈论套接字通信,只要IP地址被阻止,您就可以在连接时立即关闭与客户端的连接,或者处理连接请求并在那里进行评估。 编辑:最简单的方法可能只是与Windows防火墙API进行交互...这是如何: http://www.shafqatahmed.com/2008/01/controlling-win.html Need more information... if you're talking socket communication, you can simply close the ...
  • 由于您必须对一个表执行更新并在另外两个表上插入,因此您必须使用PL / SQL。 如果你不熟悉它,你甚至不需要光标。 只需在SELECT语句上创建一个FOR LOOP ,它就会为您提供结果集并执行3次操作(1次更新和2次插入)。 这样您就可以创建一个变量来存储序列的值,并在任意多个位置使用它。 但是如果所有的表都是空的 ,你可以在一个INSERT ALL语句中完成这个,看起来像这样 - INSERT ALL INTO RL_EST_SH(ID, PARTY_ID) VALUES (REAL_ESTATE_S ...
  • 您当前的查询选择所有行,而不管项目是否相等。 您需要修改查询,以便检查项目等于$type那些行: 改变这个: $query=mysql_query("SELECT * FROM stock"); 至: $query=mysql_query("SELECT * FROM stock WHERE item = '$type'"); Your current query selects all the rows irrespective whether the items are equal are not. ...
  • 不要担心这些选择的速度。 只要确保你有食物表中的食物索引,它应该可以存储数百万行,然后获得一排将是瓶颈。 不要陷入优化的陷阱,或者假设事情会变慢。 先试试吧。 我喜欢“真正的”键,所以我会将食物作为主键并跳过id,但正如你所说,加入int更快。 Don't worry about the speed of those selects. Just make sure you have an index on food from the foods table and it should be able sto ...
  • 一种解决方案是编写一个“INSERT之前”触发器,通过检查有多少学生随时注册该类别来强制执行业务规则等),并防止插入发生。 然后可以在更高级别检测到该错误情况,并向用户提供适当的错误消息。 在重新阅读你的问题时,业务规则也可以在你已经存在的存储过程中被检查,然后只需要让存储过程返回一个条件代码(比如说一个整数:0 = insert ok, -1 = class已满),并在应用程序级别测试此值。 编辑:更多细节(但不完整的代码...) Yuvraj,这看起来很像作业 ,所以我想让你走在正确的轨道上,但也让你对 ...
  • 不,没有单一的SSIS任务可以做到这一点。 我根本不会使用SSIS。 将逻辑放入存储过程或触发器中。 如果由于某种原因必须使用SSIS,请使用SSIS调用存储过程,或更新表并让触发器触发。 No there is no single SSIS task made to do this. I wouldn't use SSIS for this at all. Put the logic in either a stored procedure or trigger. If you have to use S ...
  • 如果您已经不使用主键和外键(您应该使用它!)我认为您可能还需要考虑在设计中使用触发器? 因此,如果您有一组特定的规则(例如,如果您想创建具有id = 1的Jane并选择现有的组2,那么在插入jane之后,人们会自动在表peoplegroups中创建一个条目对personid = 1,groupid = 2。您还可以创建具有特定选择的视图以查看所需的数据,例如,如果您希望查询只显示人员名称和组名称,则可以创建视图“PeopleView”: SELECT P.PersonName, G.GroupName FR ...
  • 您的代码似乎不正确,但包含非常糟糕的做法和不正确使用ExecuteReader 。 首先,不要使用字符串连接来构建sql命令。 这使得sql注入安全性和解析问题成为可能,因为用户输入中存在单个引号等字符。 使用参数化查询应该避免此问题。 第二。 ExecuteReader用于读取,不应用于插入数据。 虽然ExecuteReader也适用于INSERT查询,但最好使用ExecuteNonQuery来了解您的插入是否成功 ' Here the connection should be already open ...
  • 这里的主要问题是您在插入之前获取玩家详细信息。 $ getPlayerId将始终返回空结果。 请按照以下顺序进行操作。 将玩家详细信息插入到播放器表中,并使用mysql_insert_id获取payerid。 绑定后,您需要执行以向表中插入详细信息。 然后绑定并执行插入报告。 然后通过使用在步骤1中获得的playerid递增报告计数来更新播放器表。 注意:插入多个表时使用事务。 如果任何插入失败,这将帮助您回滚。 MySQL Query将返回结果对象。 请参阅https://stackoverflow.co ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)