我正在使用Long基元类型,每当我的'generateNumber'method调用时,它就会递增1.如果Long达到他的最大限制会发生什么?会抛出任何异常还是会重置为最小值?这是我的示例代码:
class LongTest {
private static long increment;
public static long generateNumber(){
++increment;
return increment;
}
}
Run Code Online (Sandbox Code Playgroud) 我完成了连接数据库(MySQL)的项目.现在我想将项目导出为jar.但我不知道如何包含其外部依赖项?有没有办法在Eclipse中执行它,或者我应该使用任何脚本吗?
我有这个类用于在Java中创建一个线程
package org.vdzundza.forms;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class DrawThread extends Thread {
private static final int THREAD_SLEEP = 500;
public CustomShape shape;
private Graphics g;
public DrawThread(CustomShape shape, Graphics g) {
this.shape = shape;
this.g = g;
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(THREAD_SLEEP);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(this.shape.getColor());
g2d.fill(this.shape.getShape());
System.out.println(String.format("execute thread: %s %s",
Thread.currentThread().getName(), this.getName()));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
控制台将以下文本显示为输出
execute thread: red rectangle Thread-2
execute …Run Code Online (Sandbox Code Playgroud) 我有一个像下面这样的方法,
public void generateCSVFile(final Date billingDate) {
asyncTaskExecutor.execute(new Runnable() {
public void run() {
try {
accessService.generateCSVFile(billingDate);
} catch (Exception e) {
LOG.error(e.getMessage());
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
我嘲笑:
PowerMockito.doNothing().when(accessService).generateCSVFile(billingDate);
Run Code Online (Sandbox Code Playgroud)
但是当我验证时:
verify(rbmPublicViewAccessService, timeout(100).times(1)).generateCSVFile(billingDate);
Run Code Online (Sandbox Code Playgroud)
它给了我没有被调用.这是因为它是通过单独的线程调用的,是否可以验证在不同线程中调用的方法?
我正在编写一个访问网络打印机的应用程序.作为该应用程序的一部分,我需要知道打印机的"状态".打印机通告其状态的唯一方法是通过SNMP.Java本身没有任何说SNMP协议的工具,所以我不知道该怎么做.如何从Java应用程序访问打印机的SNMP状态更新?
我发现JPA不支持以下更新:
Update Person p set p.name = :name_1 where p.id = :id_1,
p.name = :name_2 where p.id = :id_2,
p.name = :name_3 where p.id = :id_3
....
// It could go on, depending on the size of the input. Could be in 100s
Run Code Online (Sandbox Code Playgroud)
所以我有两个选择:
选项1:
Query q = em.createQuery("Update Person p set p.name = :name where p.id = :id");
For ( int x=0; PersonsList.length; x++ ) {
// add name and id parameters
em.executeUpdate();
}
Run Code Online (Sandbox Code Playgroud)
问题:
hibernate.jdbc.batch_size", "20"我正在尝试使用一个节点添加到副本集 rs.add("developer-ViratualBox:30103"),我收到以下错误消息:
{
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: developer-VirtualBox:30101; the following nodes did not respond affirmatively: developer-ViratualBox:30103 failed with Failed attempt to connect to developer-ViratualBox:30103; couldn't initialize connection to host developer-ViratualBox, address is invalid",
"code" : 74
}
Run Code Online (Sandbox Code Playgroud)
该节点已在运行,我使用mongoshell 连接到它.可能是什么问题?
在Hibernate是我的持久性提供程序的项目中,我可以使用'join fetch'表达式发出查询,而Hibernate将生成反映它的SQL:包含使用有效比较路径的连接表达式的SQL.
然而,EclipseLink以丑陋的笛卡尔计划发布SQL,这严重损害了性能.在阅读本文时,它提到急切的提取可能会产生笛卡儿计划,但它会方便地忘记其他提供程序(Hibernate)可以优化它.
那么,是否有可能指示EclipseLink优化这些查询?我相信通过使用@FetchJoin注释可以优化很少的关系,但我希望找到一些不包括在域模型上传播ORM特定注释的东西.
举个例子,这是我作为JPQL发布的(动态)查询:
String query = "select w from WorkOrder w " +
"inner join fetch w.type " +
"inner join fetch w.details " +
"inner join fetch w.project " +
"inner join fetch w.priority " +
"inner join fetch w.networkElement ";
Run Code Online (Sandbox Code Playgroud)
这是EclipseLink输出:
SELECT t1.ID, t1.CREATION, ... (the fetch fields here)
FROM swa_network_element t5, swa_priorities t4, swa_dispatch_project t3, swa_work_order_detail t2, swa_work_orders t1, swa_work_order_type t0
WHERE ((t1.alpha_id LIKE '%TSK%') AND (((((t0.ID = t1.TYPE_ID) AND (t2.worder_id = t1.ID)) …Run Code Online (Sandbox Code Playgroud) 我有一个EAR文件(JEE6),其中包含一个ejb-jar(sample-ejb)文件和一个war文件(sample-web).这是结构:
sample-ear
|----sample-ejb.jar
| |---TestEjb.java (@Singleton)
|
|----sample-web
|---StartupEjb.java (@Singleton,@Startup)
|---TestListener.java (@WebListener)
Run Code Online (Sandbox Code Playgroud)
当我想将TestEjb注入StartupEjb或TestListener时:
@EJB
private TestEjb testEjb;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Glassfish的:
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=com.sample.StartupEjb/testEjb,Remote 3.x interface =com.sample.TestEjb,ejb-link=null,lookup=,mappedName=,jndi-name=com.sample.TestEjb,refType=Session into class com.sample.StartupEjb: Lookup failed for 'java:comp/env/com.sample.StartupEjb/testEjb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
Run Code Online (Sandbox Code Playgroud)
weblogic的:
Caused By: weblogic.application.naming.ReferenceResolutionException: [J2EE:160200]Error resolving ejb-ref "com.sample.StartupEjb/testEjb" from module "sample-web-1.0-SNAPSHOT.war" of application "com.sample_sample-ear_ear_1.0-SNAPSHOT". The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link …Run Code Online (Sandbox Code Playgroud) 这个项目已传给我,所以我对此并不了解.有一种方法,使用log(java.util.logging.Logger)并创建两个日志文件:
第一个文件:fileName.log
第二个文件:fileName.log.lck
在Linux中,当我这样做时lsof,我看到这两个文件是打开的.如何关闭这两个文件?
我想关闭这些文件的原因是这种方法每天运行多次,几周后打开文件的数量达到一个限制(大约1000),此时我们的系统停止工作.当我们重新启动我们的进程(执行日志记录的"作业控制器")时,打开的日志文件数会变为0并再次运行.
这是做日志记录所做的
private static Logger log = Logger.getLogger(MyClass.class.getPackage().getName());
try{
log.logp(Level.SEVERE, "com.MyClass", "run", "It failed");
}
Run Code Online (Sandbox Code Playgroud)
这是我试图关闭finally块中的文件,但它不起作用
finally{
Handler[] handler = log.getHandlers();
for(Handler h: handler){
h.close();
}
}
Run Code Online (Sandbox Code Playgroud) 每当我在outputText中输入文本时,第一次点击"说出"没有异常发生,所有内容都在数据库中更新,但是当我第二次单击"说出"按钮时,我得到以下异常.
1)Home.xhtml
</div>
<div style="width:100%;background-color:#EEEEEE;">
<h:panelGrid columns="2">
<h:form>
<h:outputText value="Speak Out"/><br/>
<h:outputText value="Share whats in your mind.!" style="color:#aaaaaa;font-size:x-small;"/>
<p:inputTextarea name="content" id="sharetext" cols="60" rows="2" onclick="this.value='';" value="#{statusBean.status.statusmsg}" style="text-size:small;" /><br/>
<p:commandButton type="submit" value="Speak Out" action="#{statusBean.save}" ajax="false" styleClass="buttonstyle"/><br/>
</h:form>
<h:form>
<h:outputText value="Pic Out"/><br/>
<p:fileUpload fileUploadListener="#{statusBean.handleFileUpload}"/>
<h:outputText value="Share whats in your mind through an image.!" style="color:#aaaaaa;font-size:x-small;"/>
<p:inputTextarea name="content" id="sharetext" cols="60" rows="2" onclick="this.value='';" value="#{statusBean.status.picstatusdesc}" style="text-size:small;" /><br/>
<p:commandButton type="submit" value="Pic Out" action="#{statusBean.picSave}" ajax="false" styleClass="buttonstyle"/><br/>
</h:form>
</h:panelGrid>
</div>
Run Code Online (Sandbox Code Playgroud)
2)StatusBean.java
public class StatusBean {
Date d;
Comment comment;
Status …Run Code Online (Sandbox Code Playgroud) 我有2个表student- studLoad两个都有2个字段studID和studName.我想将student表中的数据加载到stuLoad表中.如果studLoad表中已存在数据,则应更新它,否则应插入.以下是我的代码:
create or replace procedure studentLoad is
v_id student.studID%type;
v_name student.studName%type;
v_sn studLoad.studName%type;
cursor cur_load is
select * from student;
begin
open cur_load;
loop
fetch cur_load into v_id,v_name;
exit when cur_load%notfound;
select studName into v_sn from studLoad where studID = v_id;
if(v_sn!= v_name) then
update studLoad set studName= v_name where studID= v_id;
else
insert into studLoad values(v_id,v_name);
dbms_output.put_line(v_id || ' ' || v_name);
end if;
end …Run Code Online (Sandbox Code Playgroud)