如何防止并发访问.我有这样的代码
public class MC implements Runnable {
public void run() {
sync();
}
public static void main(String p[]){
MC mc = new MC();
MC mc2 = new MC();
MC mc3 = new MC();
MC mc4 = new MC();
Thread t = new Thread(mc);
t.start();
Thread t2 = new Thread(mc2);
t2.start();
Thread t3 = new Thread(mc3);
t3.start();
Thread t4 = new Thread(mc4);
t4.start();
}
private synchronized void sync(){
try {
System.out.println(System.currentTimeMillis());
Thread.sleep(10000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个JFrame和以下组件.
JButton = jButton1 Progress Bar = progressBar及其公共静态JLabel = status及其公共静态
按钮单击时,执行不同的语句.我希望在每个语句后更新我的进度条.这是我的代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Task pbu = new Task(25, "Step 1....");
pbu.execute();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
pbu = new Task(50, "Step 2....");
pbu.execute();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
pbu = new Task(75, "Step 3....");
pbu.execute();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
pbu = new Task(100, "Done");
pbu.execute();
}
Run Code Online (Sandbox Code Playgroud)
这是我使用SwingWorker扩展的Task类
public class Task extends …Run Code Online (Sandbox Code Playgroud) 我在httpd.conf中启用了mod_cache,mod_expires,mod_headers模块,并添加了以下文本
ExpiresActive On
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds" …Run Code Online (Sandbox Code Playgroud) 例如,如果我在这样的列中有数据
data
I love book
I love apple
I love book
I hate apple
I hate apple
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到这样的结果
I = 5
love = 3
hate = 2
book = 2
apple = 3
Run Code Online (Sandbox Code Playgroud)
我们可以用 MySQL 来实现吗?
我在mysql表中有1M行,当我执行下面的代码时,我是java持久性api然后我得到java堆错误:
int counter = 0;
while (counter < 1000000) {
java.util.Collection<MyEntityClass> data = myQuery.setFirstResult(counter)
.setMaxResults(1000).getResultList();
for(MyEntityClass obj : data){
System.out.println(obj);
}
counter += 1000;
}
Run Code Online (Sandbox Code Playgroud)