我正在使用Java servlet开发一个Web应用程序来访问Mysql数据库,如何获取当前打开的数据库连接数?
编辑:
我试过"show processlist",它告诉我:2695159,但那不对,我只是在开发这个新项目,我是唯一的用户,没有那么多进程在运行,我想要的是数量用户访问我项目的数据库,而不是所有数据库用户的数量,而只是登录到我的数据库的只有一个表的用户.
我问如何在Java中检测日期是在本周还是下周?但答案令人困惑,所以现在我想如果我能找到过去的星期天和即将到来的星期日,那么这一周中的任何一天都是本周,而在即将到来的星期日和星期日之间的任何一天都是下周,我是否正确?
所以我的新问题是:如何在Java中过去的星期天和即将到来的星期天?
我有以下应用程序绘制规则:
public class Rule extends JComponent
{
public static final long serialVersionUID=26362862L;
// public static final int INCH=Toolkit.getDefaultToolkit().getScreenResolution();
public static final int INCH=(int)(Toolkit.getDefaultToolkit().getScreenResolution()*1.15); // Auto adjust this 1.15 ?
public static final int HORIZONTAL=0;
public static final int VERTICAL=1;
public static final int SIZE=35;
public int orientation;
public boolean isMetric;
private int increment;
private int units;
// private Color rule_color=new Color(0,135,235);
private Color rule_color=new Color(120,170,230);
static JFrame frame=new JFrame("Rule");
static Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); // 1600 x 1200 , 1024 x 768 …Run Code Online (Sandbox Code Playgroud) 我写了一个应用程序,我想在网上销售它,所以我上传到我的网站并尝试下载并运行它作为测试,但是出现了一个窗口,它说:"发布者无法验证.你确定你想运行这个软件吗?",它还说:"出版商:未知出版商".它实际上是一个包装在exe文件中的自签名Java jar文件,我用Netbeans6.7自行签名.
我想知道如何才能成为"知名"出版商?
坦率
我正在使用Google App Engine处理Paypal IPN消息,当我的servlet启动时,我使用以下行开始另一个流程来处理按摩:
public class PayPal_Monitor_Servlet extends HttpServlet
{
PayPal_Message_To_License_File_Worker PayPal_message_to_license_file_worker;
public void init(ServletConfig config) throws ServletException // Initializes the servlet.
{
super.init(config);
PayPal_message_to_license_file_worker=new PayPal_Message_To_License_File_Worker();
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
{
}
...
}
public class PayPal_Message_To_License_File_Worker implements Runnable
{
static Thread PayPal_Message_To_License_File_Thread;
...
PayPal_Message_To_License_File_Worker()
{
start();
}
void start()
{
if (PayPal_Message_To_License_File_Thread==null)
{
PayPal_Message_To_License_File_Thread=new Thread(this);
PayPal_Message_To_License_File_Thread.setPriority(Thread.MIN_PRIORITY);
PayPal_Message_To_License_File_Thread.start();
}
...
}
Run Code Online (Sandbox Code Playgroud)
但是"PayPal_Message_To_License_File_Thread = new Thread(this);" 导致以下错误:
javax.servlet.ServletContext log: unavailable
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355) …Run Code Online (Sandbox Code Playgroud) 我在我的多线程应用程序中使用了Java Executors,但我似乎无法弄清楚何时最好使用以下各种方法:
1.
ExecutorService executor=Executors.newFixedThreadPool(50);
executor.execute(new A_Runner(... some parameter ...));
executor.shutdown();
while (!executor.isTerminated()) { Thread.sleep(100); }
Run Code Online (Sandbox Code Playgroud)
2.
int Page_Count=200;
ExecutorService executor=Executors.newFixedThreadPool(50);
doneSignal=new CountDownLatch(Page_Count);
for (int i=0;i<Page_Count;i++) executor.execute(new A_Runner(doneSignal, ... some parameter ...));
doneSignal.await();
executor.shutdown();
while (!executor.isTerminated()) { Thread.sleep(100); }
Run Code Online (Sandbox Code Playgroud)
3.
int Executor_Count=30;
ThreadPoolExecutor executor=new ThreadPoolExecutor(Executor_Count,Executor_Count*2,1,TimeUnit.SECONDS,new LinkedBlockingQueue());
List<Future<String>> futures=new ArrayList<>(3330);
for (int i=0;i<50;i++) futures.add(executor.submit(new A_Runner(... some parameter ...));
executor.shutdown();
while (!executor.isTerminated()) { executor.awaitTermination(1,TimeUnit.SECONDS); }
for (Future<String> future : futures)
{
String f=future.get();
// ...
}
Run Code Online (Sandbox Code Playgroud)
具体来说,在[2]中,如果我跳过doneSignal,那么它就像[1],那么doneSignal的用途是什么?
另外,在[3]中,如果我添加一个doneSignal怎么办?或者有可能吗?
我想知道的是:这些方法是否可以互换,或者是否存在我应该使用上述特定类型的某种情况?
java multithreading executorservice java.util.concurrent threadpoolexecutor
我使用以下代码将中文字符保存到.txt文件中,但是当我用Wordpad打开它时,我无法读取它.
StringBuffer Shanghai_StrBuf = new StringBuffer("\u4E0A\u6D77");
boolean Append = true;
FileOutputStream fos;
fos = new FileOutputStream(FileName, Append);
for (int i = 0;i < Shanghai_StrBuf.length(); i++) {
fos.write(Shanghai_StrBuf.charAt(i));
}
fos.close();
Run Code Online (Sandbox Code Playgroud)
我能做什么 ?我知道如果我将中文字符剪切并粘贴到Wordpad中,我可以将其保存到.txt文件中.我如何用Java做到这一点?
我有一台运行Win Vista的PC笔记本,当我第一次买它时,某些中文字体不会出现,我只能看到矩形,但是我用控制设置播放了一段时间,改了一些属性,现在它显示了中文字体正确,但我不记得我做了什么.
现在我的一些程序显示英文和中文,如下所示:"输入|输入"(这里的中文也意味着输入),但如果用户没有在他的机器上正确安装中文字体,他会看到像这个:"输入| [] []",我的问题是:在Java中如何检测这些字符是否会在某台机器上正确显示,如果没有,只显示"Enter",如果是,则显示"Enter | Enter into ".
坦率
我发现了一篇关于如何从雅虎下载历史日内数据的在线文章:http://www.quantshare.com/sa-426-6-ways-to-download-free-intraday-and-tick-data-for-在美国,股市
但是如何获得一个特定日的股票历史日内数据呢?例如,如何在2013-01-31获取IBM的一分钟间隔数据?
除雅虎之外,还有其他任何地方免费提供一天的历史日内数据吗?