java web 处理大量用户并发提交的简单思路:队列加定时提交
模拟简单程序代码如下:
- package cn.zz.lc.test;
-
- import java.util.LinkedList;
- import java.util.Queue;
-
- public class TestQueue {
- public static void main(String[] args) throws InterruptedException {
- Queue<String> queue = new LinkedList<String>();
- for (int i = 0; i < 65; i++) {
- queue.offer("queue emement:" + i);
- }
- System.out.println(queue.size());
- String str;
- int j = 1;
- while (!queue.isEmpty()) {
- int k = 10;
- while ((str = queue.poll()) != null) {
- System.out.println(str);
- k--;
- if (k == 0) {
- break;
- }
- }
- System.out.println("第" + j + "次提交!");
- j++;
- Thread.sleep(5000);
- }
-
- System.out.println("===================================");
- System.out.println(queue.size());
- }
-
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。