Tag: fifo

Java Pig拉丁语句子翻译使用队列

我是Java的新手,我正在尝试创建一个程序,将一个句子翻译成Pig Latin,将单词的第一个字母移到最后,如果第一个字母是元音,则在末尾添加“y”并且“ay”最后,否则。 我需要为此使用队列。 目前我的计划正在终止,我想知道是否有人能够找到我出错的地方或下一步去哪里。 谢谢! import MyQueue.QueueList; import java.util.Scanner; 公共类PigLatin { public static void main (String[] args) { Scanner scan = new Scanner (System.in); QueueList word = new QueueList(); String message; int index = 0; char firstch; System.out.print (“Enter an English sentence: “); message = scan.nextLine(); System.out.println (“The equivalent Pig Latin sentence is: “); firstch […]

如何保证ThreadPoolExecutor中的FIFO执行顺序

我用这行代码创建一个ThreadPoolExecutor: private ExecutorService executor = new ThreadPoolExecutor(5, 10, 120, TimeUnit.SECONDS, new ArrayBlockingQueue(20, true)); 然后,我运行25个任务(T01到T25),所以情况是: 当前正在运行的5个任务(T01到T05) 在队列中等待的20个任务(T06到T25) 当我再添加1个任务(T26)时,当队列已满时,我预计将删除旧任务(T06)以启动(因为未达到MaxPoolSize)并且新任务(T26)被放置在末尾队列。 但在现实生活中,如果Queue已满并且未达到MaxPoolSize,则启动最新任务。 所以我有 … 当前正在运行的6个任务(T01到T05和T26) 在队列中等待的20个任务(T06到T25) … 代替 … 当前正在运行的6个任务(T01到T06) 在队列中等待的20个任务(T07到T26) 我可以配置ThreadPoolExecutor来获得预期的结果吗? 我应该使用其他课吗? 有关信息,部分ThreadPoolExecutor源代码 public void execute(Runnable command) { if (command == null) throw new NullPointerException(); if (poolSize >= corePoolSize || !addIfUnderCorePoolSize(command)) { if (runState == RUNNING && workQueue.offer(command)) […]

为什么将队列实现为循环数组?

当实现像队列这样的FIFO时,我的教师总是建议我们将它表示为圆形数组而不是常规数组。 为什么? 是因为在后者中,我们最终会在arrays中有垃圾数据吗?

重定向应用程序(java)的输入,但仍允许在BASH中使用stdin

我有点困惑,我昨天有这个工作,但它刚刚停止接受重定向的标准输入,几乎是神奇的。 set -m mkfifo inputfifo mkfifo inputfifo_helper ((while true; do cat inputfifo; done) > inputfifo_helper)& trap “rm -f inputfifo inputfifo_helper java.pid; kill $!” EXIT exec 3<&0 (cat inputfifo)& NOW=$(date +”%b-%d-%y-%T”) if ! [ -d “logs” ]; then mkdir logs fi if [ -f “server.log” ]; then mv server.log logs/server-$NOW.log fi java java.pid && fg 运行正常,我可以回复inputfifo并且应用程序得到它,我也可以直接输入它的控制台。 […]