List<String> list = Collections.synchronizedList(new ArrayList<String>());
synchronized (list) {
list.add("message");
}
Run Code Online (Sandbox Code Playgroud)
块"synchronized(list){}"真的需要吗?
我正在使用Apache HttpClient 4,它工作正常.唯一不起作用的是自定义端口.似乎提取了根目录并忽略了端口.
HttpPost post = new HttpPost("http://myserver.com:50000");
HttpResponse response = httpClient.execute(post);
Run Code Online (Sandbox Code Playgroud)
如果没有定义端口,则http-和https-connections运行良好.方案登记处的定义如下:
final SchemeRegistry sr = new SchemeRegistry();
final Scheme http = new Scheme("http", 80,
PlainSocketFactory.getSocketFactory());
sr.register(http);
final SSLContext sc = SSLContext.getInstance(SSLSocketFactory.TLS);
sc.init(null, TRUST_MANAGER, new SecureRandom());
SSLContext.setDefault(sc);
final SSLSocketFactory sf = new SSLSocketFactory(sc,
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
final Scheme https = new Scheme("https", 443, sf);
sr.register(https);
Run Code Online (Sandbox Code Playgroud)
如何为请求定义自定义端口?
我正在通过Jsch上传SFTP的大文件.在上传过程中,旧文件应该可用,因此我上传到临时文件并将其重命名为新文件.
final String tmpName = dest + "_tmp";
channel.put(source, tmpName);
channel.rename(tmpName, dest);
Run Code Online (Sandbox Code Playgroud)
上传没问题,但重命名失败:
ERROR: Failed to upload files
4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2491)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1665)
...
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚问题出在哪里.请帮忙
我想设置JPopupMenu打开菜单的按钮的y位置的位置.我的代码在我的第一台显示器上工作正常,但在我的第二台显示器上失败,它有不同的高度.问题是getLocationOnScreen()提供相对于主屏幕的位置,而不是显示组件的实际屏幕.
我的代码:
// screenSize represents the size of the screen where the button is
// currently showing
final Rectangle screenSize = dateButton.getGraphicsConfiguration().getBounds();
final int yScreen = screenSize.height;
int preferredY;
// getLocationOnScreen does always give the relative position to the main screen
if (getLocationOnScreen().y + dateButton.getHeight() + datePopup.getPreferredSize().height > yScreen) {
preferredY = -datePopup.getPreferredSize().height;
} else {
preferredY = getPreferredSize().height;
}
datePopup.show(DateSpinner.this, 0, preferredY);
Run Code Online (Sandbox Code Playgroud)
如何在实际监视器上获取组件的位置?