随着时间的推移,Sun的JVM和JIT变得非常聪明.以前不再需要将常识作为必要的微优化的东西,因为它会得到照顾.
例如,过去应该将所有可能的类标记为final,因此JVM会尽可能多地内联代码.但是现在,JIT根据在运行时加载的类知道你的类是否是最终的,如果加载一个类使原始类不可能,它会取消内联方法并取消标记为最后.
JVM或JIT还为您做了哪些其他智能微优化?
编辑:我把它做成了社区维基; 我想随着时间的推移收集它们.
我有一个服务,它接收一个DTO并返回一些结果:
@Override
public int foo(Bar bar) {
....
}
Run Code Online (Sandbox Code Playgroud)
栏如下(简化):
public class Bar {
public int id;
public String name;
public String baz;
@Override
public int hashCode() {
//this is already being defined for something else
...
}
@Override
public boolean equals(Object o) {
//this is already being defined for something else
...
}
}
Run Code Online (Sandbox Code Playgroud)
我想在foo方法上使用@Cacheable; 但是,我想在id和name属性上哈希,但不是baz.有没有办法做到这一点?
当我在本地提出请求时,我没有任何问题维护我的FlexSession; 但是,当我从另一台计算机发出请求时,它会为每个请求创建重复的FlexSession.我注意到每个请求的JSESSIONID都不同,这可能会导致欺骗性会话.
但我不知道为什么会这样.我得到的具体错误是:
Channel.Ping.Failed error Detected duplicate HTTP-based FlexSessions, generally due to the remote host disabling session cookies. Session cookies must be enabled to manage the client connection correctly.
Run Code Online (Sandbox Code Playgroud)
我的crossdomain.xml如下:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>
Run Code Online (Sandbox Code Playgroud)
编辑:
我们在后端使用spring-flex集成.此外,这发生在多个浏览器中; 我们尝试过IE,Firefox和Chrome.
这是Flex代码:
var ro : RemoteObject = new RemoteObject("myDestination");
ro.endpoint = "http://localhost/foo";
ro.source = "com.bar.MyService";
var op : AbstractOperation = ro.getOperation("serviceMethod");
op.addEventListener( FaultEvent.FAULT, ro_faultHandler );
op.addEventListener( ResultEvent.RESULT, ro_resultHandler );
op.send();
Run Code Online (Sandbox Code Playgroud) 我需要POST一个REST服务调用并获取它返回的数据(所有这些都是使用JSON).我有一个出站网关,其回复通道作为链,链有一个变压器.
<int-http:outbound-gateway
url="#{appProperties['rootUrl']}#{appProperties['myMethod']}"
request-channel="myRequestChannel" reply-channel="myResponseChannel" >
</int-http:outbound-gateway>
<int:channel id="myResponseChannel"/>
<int:chain input-channel="myResponseChannel">
<int:transformer ref="genericResponseTransformer"/>
</int:chain>
Run Code Online (Sandbox Code Playgroud)
但是当我通过变换器调试时,我得到的有效负载只是一个HttpStatus对象.
也许我做错了什么?任何帮助将不胜感激.谢谢!
我的问题是,当我在多对多关系中插入一个实体时,我无法获得在链接表中自动生成的 ID。
我在实体 Foo 和 Bar 之间存在双向多对多关系。名为 FOO_BAR 的链接表具有 FOO_BAR_ID、FOO_ID 和 BAR_ID,第一个是表上的 PK。它链接 FOO 和 BAR 表,它们也有自己的 PK、FOO_ID 和 BAR_ID。这两个扩展自一个公共基类,该基类具有带有序列生成器的 @Id。
public abstract class ParentEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
@SequenceGenerator(name = "generator", sequenceName = "some_sequence")
protected Long id;
//...getters/setters
}
Run Code Online (Sandbox Code Playgroud)
实体 Foo 位于 FOO 表中,其 PK 名为 FOO_ID。
@Entity
@Table(name = "FOO")
@AttributeOverride(name = "id", column = @Column(name = "FOO_ID"))
public class Foo extends ParentEntity {
@Column(name = "name")
protected String name;
@ManyToMany(cascade …
Run Code Online (Sandbox Code Playgroud) 我有一个web-app(2.5 servlet规范),一个spring dispatcherservlet处理任何正在/ error/*上的内容和一个错误页面,配置为将其路由到/ error /这样的东西:
<servlet>
<servlet-name>errorServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>errorServlet</servlet-name>
<url-pattern>/erorr/*</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/erorr/</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
和errorServlet-servelt.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="some.base.package"/>
<bean id="simpleUrlController" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/*">errorController</prop>
</props>
</property>
</bean>
<bean id="errorController" class="ErrorController">
<property name="formView" value="formView"/>
<property name="commandClass" value="Error"/>
<property name="commandName" value="errorNAMe"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
我需要帮助的地方:
是否有一个在MS Access和SQLServer 2k5 +中都可以将字符串转换为日期的函数?似乎CDate在访问和转换工作在SQLServer中工作,但我想要一个兼容的功能.
谢谢!
我意识到在SO上有类似的问题,但它们并没有完全解决我的问题.
我想要一个方法,给定一个Class对象,将调用该类上的"main"方法,即public static void main(如果存在)并捕获该main方法的控制台输出.执行调用的类是非守护程序线程.
我已经有了部分代码,但是我不知道如何捕获控制台输出,最重要的是,如何只为这个特定的线程捕获它.这是我到目前为止所拥有的:
public class Output extends Thread {
private Class testClass;
public Output(Class clazz) {
this.testClass = clazz;
}
private Method getMainMethod(Class clazz) {
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (isMainMethod(method)) {
return method;
}
}
return null;
}
private Boolean isMainMethod(Method method) {
return (method.getName().equals("main") &&
Modifier.isStatic(method.getModifiers()) &&
method.getReturnType().equals(Void.class));
}
public void run() {
Method mainMethod = null;
if ((mainMethod = getMainMethod(this.testClass)) == null) {
//if there's no static void …
Run Code Online (Sandbox Code Playgroud) 有没有什么办法可以在JDK 6上运行用Java 5编译的类文件(即使用main作为入口点)?
我不太确定这叫做什么,但我花了一些时间思考它,我不知道如何处理它.我确信这很简单.
我有两张桌子,foo和bar.他们是这样的:
Foo表:
| id | name
--------------
| 1 | blah
| 2 | blarg
| 3 | blag
Run Code Online (Sandbox Code Playgroud)
条形图表(baz的含义无关紧要):
| fooId | baz |
---------------
| 1 | 100 |
| 1 | 94 |
| 1 | 27 |
| 2 | 94 |
| 3 | 19 |
Run Code Online (Sandbox Code Playgroud)
所以,每个Foo多个Bars.我想选择所有他们的baz为94的Foos,除非他们的baz为100.所以在上面的例子中我只想选择id为2的Foo.
我试着按照以下方式做一些事情:
SELECT id FROM foo
LEFT JOIN bar
ON foo.id = bar.fooId
WHERE bar.baz = 94
AND bar.baz != 100
Run Code Online (Sandbox Code Playgroud)
但很明显,到目前为止只有我.我确定这里可能有某种group by子句,但我不确定它应该是什么.
提前致谢!
编辑:如果其他人有这个问题,正如 …
string host = "http://youtube.com/v/";
string end = ".flv";
WebClient Client = new WebClient ();
StreamReader sr = new StreamReader(@"ids.txt");
string line;
do
{
line = sr.ReadLine();
Client.DownloadFile(host+line+end,line+end);
}
while (line !=null);
sr.Close();
Run Code Online (Sandbox Code Playgroud)
工作正常但晚于我将运行flv /视频,这给了我这个错误>
An error occurred when the file plays in Windows Media Player
Run Code Online (Sandbox Code Playgroud)
为什么,我做错了什么?
java ×6
spring ×2
blazeds ×1
c# ×1
caching ×1
compilation ×1
console ×1
cross-domain ×1
flash ×1
flex4 ×1
flv ×1
flvplayback ×1
gateway ×1
hibernate ×1
java-5 ×1
java-6 ×1
jit ×1
join ×1
jpa ×1
jvm ×1
many-to-many ×1
methods ×1
ms-access ×1
oracle ×1
oracle10g ×1
payload ×1
rounding ×1
sequence ×1
session ×1
spring-mvc ×1
sql ×1
sql-server ×1
velocity ×1
youtube ×1