我是JMS的新手,我正在尝试加载一个connectionFactory.我遵循了几个教程,但由于某些原因它似乎不起作用,每次我尝试'.lookup'connectionfactory时我都会得到一个例外.我正在使用JBoss7.1.
这是我正在尝试获取connectionFactory的类:
public class QueueSend extends Frame implements ActionListener {
private QueueConnectionFactory qconFactory;
private QueueConnection qcon;
private QueueSession qsession;
private QueueSender qsender;
private Queue queue;
private TextMessage msg;
private TextField tf=new TextField();
private Button send=new Button("Send");
public QueueSend(){
super("Queue Sender");
setLocation(150,50);
setSize(200,100);
add(tf);
add(send,BorderLayout.SOUTH);
send.addActionListener(this);
send.setEnabled(false);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
send("quit");
close();
System.exit(0);
}
});
setVisible(true);
init();
}
public void init(){
try{
InitialContext ctx = getInitialContext();
qconFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
queue = (Queue) ctx.lookup("java:/queue/text");
qcon = qconFactory.createQueueConnection();
qsession …Run Code Online (Sandbox Code Playgroud) 我有一个框架,图像覆盖它,我希望每次有人点击图像中的不同对象,它将作为一个按钮,做一些事情.
问题是,这些对象是不是简单的形状,所以我想在这些对象的形状中绘制我自己的隐形按钮.
那可能吗?或者什么是更好的方式来完成这样的事情?
-谢谢
我正在尝试创建一个,InitialContext所以我可以向JNDI询问一些企业java bean.JBoss运行正常,但是当我运行java代码时,我得到了一个异常.
我正在运行JBoss 7.1
这是我的代码:
public class Test {
public static void main(String[] args){
InitialContext ctx=getInitialContext();
Object ref=null;
try {
ref = ctx.lookup("ParamEJB/remote");
} catch (NamingException e) {
System.out.println("Lookup Failed");
e.printStackTrace();
}
Param stub=(Param)PortableRemoteObject.narrow(ref, Param.class);
int times=stub.getTimes();
for(int i=0;i<times;i++)
System.out.println(stub.getMessage());
}
public static InitialContext getInitialContext(){
Hashtable<String,String> h=new Hashtable<String,String>();
h.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
h.put("java.naming.provider.url","localhost");
try {
return new InitialContext(h);
} catch (NamingException e) {
System.out.println("Cannot generate InitialContext");
e.printStackTrace();
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
在我启动JBoss服务器之后,我尝试运行java代码并得到以下异常:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is …Run Code Online (Sandbox Code Playgroud) 当我试图杀死我的强盗线程时,有些人死了,但有些人陷入了wait()阻止,什么是杀死所有线程的更好方法,或者我如何让被阻止的线程被杀死?
private int robberId;
private static int robberGlobalId=0;
private TreasureChest chest;
private boolean alive = true;
public Robber(TreasureChest chest) {
robberId = robberGlobalId;
robberGlobalId++;
this.chest = chest;
}
public void run() {
while (alive) {
try {
synchronized(chest){
robCoin();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Robber " +robberId +" just died");
}
public void robCoin() throws InterruptedException {
if (chest.getTreasureAmount() <= 0 ) {
chest.wait();
} else {
chest.removeCoin();
}
Thread.sleep(50);
}
public void killRobber() {
alive …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用sqljdbc4连接到我的数据库,我对此很新,所以我遵循了几个教程,但它似乎仍然无法工作,当我尝试运行程序时,我得到了这个例外:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:f181fd37-7e28-4392-ac86-02914c2090e1
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=DBank;","","");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
Run Code Online (Sandbox Code Playgroud) 为什么这两个整数
Long num = new Long(21);
long num2 = 21;
Run Code Online (Sandbox Code Playgroud)
比较时返回true(num == num2)
但是这个字符串
String word1 = "Hello";
String word2 = new String("Hello");
Run Code Online (Sandbox Code Playgroud)
比较时返回false(word1 == word2)?