如果你在enum api中查看方法,name()它会说:
返回此枚举常量的名称,与其枚举声明中声明的完全相同.大多数程序员应优先使用toString方法,因为toString方法可能会返回一个更加用户友好的名称.此方法主要用于特殊情况,其中正确性取决于获取确切名称,该名称在不同版本之间不会有所不同.
为什么更好用toString()?我的意思是当name()已经是final时,可以覆盖toString.因此,如果您使用toString并且有人覆盖它以返回硬编码值,则整个应用程序都会关闭...另外,如果您查看源代码,则toString()方法将返回完全正确的名称.这是同一件事.
我正在使用Spring 4,我注意到一个奇怪的行为......如果我从普通实例方法多次调用异步方法,那么它们都会在不同的线程中调用并随机完成.但是,如果我从另一个异步方法多次调用异步方法,那么它们按顺序完成.我有这样的事情:
@Async
public void nonAsyncMethod() {
for (int i = 0; i < 30; i++) {
asyncMethod();
}
}
@Async
public void asyncMethod() {
... something here
}
Run Code Online (Sandbox Code Playgroud)
我正在使用默认的异步执行程序.我应该使用另一个吗?然而,这个执行器不会重复使用任何线程并且每次都启动另一个线程所以它应该没问题......它只是巧合吗?但我尝试过10次以上,如果我恢复到第一种方法的非异步,那么他们会随机完成
Java中创建单例的最佳方法是什么?数据库连接应该是单例(单例是否是自动线程安全的)?因为理论上DB不能同时被许多用户访问.
假设我有一个类Comment,我有一个名为commentDate的私有字段,它是一个java.util.Date,并带有一个名为getCommentDate的getter .
为什么最好返回该日期的副本(返回新日期(commentDate.getTime()))而不是简单地返回该日期...
用户如何更改该Date的对象状态,因为它是getter而不是setter?
我使用JSF 2作为视图,使用Spring作为业务逻辑.我正在尝试使用注释(@Scope("session"))将会话范围设置为我的一个spring bean,但是我得到了这个异常:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleFiles': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private creazione.util.FTPOperations creazione.components.HandleOldFiles.operations;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'ftpOperations': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton;
nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用httpd代理和反向代理配置websockets但它似乎不起作用.如果我直接使用tomcat服务器一切都很好,如果我通过apache httpd调用它,响应状态为200.这意味着apache httpd无法解释websocket请求并切换协议,对吧?
这是我的应用程序的httpd配置:
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
Listen 443 https
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
SSLSessionCache shmcb:/run/httpd/sslcache(512000)
SSLSessionCacheTimeout 300
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
<VirtualHost 10.224.130.50:80>
ServerName myhost
Redirect permanent / https://myhost/
</VirtualHost>
<VirtualHost 10.224.130.50:443>
ServerName myhost
ErrorLog logs/myhost.error.log
CustomLog logs/myhost.access.log common
ProxyPass /ws/ wss://localhost:8443/ws/ retry=0
ProxyPassReverse /ws/ wss://localhost:8443/ws/ retry=0
ProxyPass / https://myhost:8443/ connectiontimeout=600 timeout=1200
ProxyPassReverse / https://myhost:8443/
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
SSLCertificateFile …Run Code Online (Sandbox Code Playgroud) 是否可以将Jenkins配置为使用多个Sonar实例?
目前,我们正在为遗留项目(Java 6)使用一个Sonar实例,为Java 8使用新的Sonar实例