为了在Java中获得最快的TCP传输速度,这是更好的:
选项A:
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
Run Code Online (Sandbox Code Playgroud)
选项B:
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
Run Code Online (Sandbox Code Playgroud)
我已经读过,当将8 KiB写入OutputStream时,性能会受到影响,建议它一次性写入小块而不是pver 8 KiB.8 KiB是BufferedOutputStream的默认缓冲区大小.
但是我还读到,当通过网络传输数据时,尽可能快地清除字节是很好的.这意味着使用缓冲区并以小块写入会增加不必要的开销.
那么,选项A还是选项B?哪个效果最好?
现在我猜测选项A提供了最高的传输速度,同时消耗了比选项B更多的CPU.选项B可能更好,因为它没有那么慢,但节省了大量的CPU.
-
奖金问题:触摸TCP窗口大小是个好主意吗?例如,将其设置为64 KiB:
socket.setReceiveBufferSize(65536);
socket.setSendBufferSize(65536);
Run Code Online (Sandbox Code Playgroud)
我尝试在测试机器上将其设置为128 KiB,因为我读到它可以提高速度但是当服务器有几个连接时,CPU是100%而不是2%,就像我单独离开时一样.我猜128 KiB太高了,除非你有一台能够处理流量急流的好服务器,但将它设置为32 KiB是否明智?我认为我的默认值是8 KiB.
("socket"是"java.net.Socket")
在调整我的构建文件,我似乎 已经遇到了一个错误有mainClassName:
thufir@dur:~/NetBeansProjects/HelloSeleniumWorld$
thufir@dur:~/NetBeansProjects/HelloSeleniumWorld$ ./gradlew clean ShadowJar --stacktrace
> Task :shadowJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':shadowJar'.
> No value has been specified for property 'mainClassName'.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskValidationException: A problem was found with the configuration …Run Code Online (Sandbox Code Playgroud) 如何将输出连接到paneWithList?
PaneWithList它上面有一个监听器,JList以便将选定的行输出到控制台.如何将输出定向到JTextPane输出?
可以PaneWithList解雇一个Main接收的事件吗?会的PropertyChangeSupport足够?
Main.java:
package dur.bounceme.net;
import javax.swing.JTabbedPane;
public class Main {
private static JTabbedPane tabs;
private static PaneWithList paneWithList;
private static PaneWithTable paneWithTable;
private static Output output;
public static void main(String[] args) {
tabs = new javax.swing.JTabbedPane();
paneWithList = new PaneWithList();
paneWithTable = new PaneWithTable();
tabs.addTab("list", paneWithList);
tabs.addTab("table", paneWithTable);
tabs.addTab("output", output);
}
}
Run Code Online (Sandbox Code Playgroud) 最简单的Kotlin hello world for gradle script Kotlin:
thufir@dur:~/github/gradleScriptKotlin$
thufir@dur:~/github/gradleScriptKotlin$ gradle clean shadowJar;java -jar build/libs/gradleScriptKotlin.jar
> Task :compileKotlin
Using Kotlin incremental compilation
> Task :shadowJar
A problem was found with the configuration of task ':shadowJar'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
- No value has been specified for property 'mainClassName'.
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle …Run Code Online (Sandbox Code Playgroud) 希望records在gradle构建中使用Java 14 ,但我得到:
thufir@dur:~/NetBeansProjects/FileWatcherHandler$
thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build
> Task :compileJava FAILED
/home/thufir/NetBeansProjects/FileWatcherHandler/src/main/java/net/bounceme/dur/files/FXOrder.java:3: error: records are a preview feature and are disabled by default.
public record FXOrder(int units) {}
^
(use --enable-preview to enable records)
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info …Run Code Online (Sandbox Code Playgroud) 对于"hello world"类型的xml文档:
<?xml version="1.0" encoding="UTF-8"?>
<!-- see http://www.w3.org/TR/REC-xml-names/ -->
<bk:book xmlns:bk="urn:loc.gov:books" xmlns:isbn="urn:ISBN:0-395-36341-6">
<bk:title>Cheaper by the Dozen</bk:title>
<isbn:number>1568491379</isbn:number>
</bk:book>
Run Code Online (Sandbox Code Playgroud)
你可以随意定义urn用于自定义目的吗?
如何通过 gradle 添加 javafx 依赖项?
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$
thufir@dur:~/NetBeansProjects/helloWorldJavaFX$ gradle clean
> Configure project :
e: /home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts:13:7: Unresolved reference: openjfx
FAILURE: Build failed with an exception.
* Where:
Build file '/home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts' line: 13
* What went wrong:
Script compilation error:
Line 13: org.openjfx.javafxplugin
^ Unresolved reference: openjfx
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help …Run Code Online (Sandbox Code Playgroud) 如果我不能将@ManagedProperty注释与@Named一起使用,因为@ManagedProperty在CDI(?)中不起作用,那么如何将URL中的params传递给facelets客户端?在我的代码中,我想通过"后退"和"前进"按钮将javax.mail.getMessageNumber()传递给details.xhtml.
我知道应该使用@Inject,但是注入的是什么,请问?
从glassfish日志中,id总是0,这很奇怪.即使单击"前进",无论单击按钮多少次,ID都不会超过1.当然,这仅仅是问题的症状.当然,所需的输出是前进到下一个消息.
也许将Message或者至少是int放入会话中?
客户端如此:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="top">
<h:form>
<h:form>
<h:outputLink id="link1" value="detail.xhtml">
<f:param name="id" value="#{detail.back()}" />
<h:outputText value="back" />
</h:outputLink>
</h:form>
</h:form>
<h:form>
<h:outputLink id="link1" value="detail.xhtml">
<f:param name="id" value="#{detail.forward()}" />
<h:outputText value="forward" />
</h:outputLink>
</h:form>
</ui:define>
<ui:define name="content">
<h:outputText value="#{detail.content}"></h:outputText>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
和bean一样:
package net.bounceme.dur.nntp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import javax.mail.Message;
@Named
@RequestScoped
public class Detail …Run Code Online (Sandbox Code Playgroud) 基于axtavt的答案,这几乎肯定是Notebean和NoteBean之间的命名问题.这里有一个特定的惯例,只是正常的CamelCase吗?
我相信我已经更新了实体中的@NamedQuery注释,并且正在使用来自控制器的注释,并且名称看起来匹配,但我仍然收到关于模式的相同错误,我无法获得更多信息上.
JPA控制器:
package net.bounceme.dur.nntp.controller;
import java.util.*;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.persistence.*;
import javax.swing.DefaultListModel;
import net.bounceme.dur.nntp.model.NoteBean;
public class NotesController {
private static final long serialVersionUID = 1L;
private static final Logger LOG = Logger.getLogger(NotesController.class.getName());
private Message message;
private List<NoteBean> notes = new ArrayList<NoteBean>();
private DefaultListModel defaultListModel = new DefaultListModel();
private EntityManagerFactory emf;
private EntityManager em;
private String PERSISTENCE_UNIT_NAME = "nntpPU";
public NotesController() {
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = emf.createEntityManager();
LOG.info("entity manager made???" + em.isOpen());
populateList();
}
private void populateList() …Run Code Online (Sandbox Code Playgroud) 我的问题是,在运行任何Web应用程序后,我收到此消息.例如,在netbeans我创建新项目并选择webapplication我保留所有默认值我不会更改名称.
然后我第一次部署它,但是当我关闭netbeans并稍后打开它并尝试部署在我得到该错误之前工作的相同项目,没有首先它被卡在"启动GlassFish Server 4"然后我停止它重新部署,我得到
Starting GlassFish Server 4
GlassFish Server 4 is running.
In-place deployment at C:\Users\****\Documents\NetBeansProjects\WebApplication1\build\web
GlassFish Server 4, deploy, Connection refused: connect, false
C:\Users\***\Documents\NetBeansProjects\WebApplication1\nbproject\build-impl.xml:1045: The
module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 8 seconds)
Run Code Online (Sandbox Code Playgroud)
所以这让我的考试花费了我,因为我不知道该如何应对它,感到如此无能为力是一种毁灭性的,我立刻迷失方向,在我知道之前,是时候交出我们的工作而且我还是被卡住了在第一个任务和每个其他任务取决于第一个任务的成功.无论如何,从那以后我一直在删除glassfish并重新安装以使其工作(太糟糕了我在考试期间考虑到这一点,也应该更多地关注实践而不是理论然后我可以看到问题).
尝试添加netbeans到防火墙,更改端口和其他人建议的其他东西,仍然没有运气,结果总是相同我甚至使用一个全新的虚拟机,我仍然得到相同的消息,当我关闭netbeans并稍后重新打开它.再次当我删除glassfish并重新安装它我工作得很好.
这是我的服务器日志,道歉,我不知道如何使它漂亮.服务器日志:
[2014-09-13T04:14:44.926+0200] [glassfish 4.1] [INFO] [NCLS-LOGGING-00009] [javax.enterprise.logging] [tid: _ThreadID=17 _ThreadName=RunLevelControllerThread-1410574484853] [timeMillis: 1410574484926] [levelValue: 800] [[
Running GlassFish Version: GlassFish Server Open Source Edition 4.1 (build 13)]]
[2014-09-13T04:14:44.928+0200] [glassfish 4.1] [INFO] [NCLS-LOGGING-00010] [javax.enterprise.logging] [tid: _ThreadID=17 …Run Code Online (Sandbox Code Playgroud)