小编art*_*ved的帖子

暂停ScheduledExecutorService

我使用a ScheduledExecutorService来执行以固定速率调用服务的任务.该服务可能会将一些数据返回给任务.该任务将数据存储在队列中.其他一些线程慢慢从队列中挑选项目

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class EverlastingThread implements Runnable {

    private ScheduledExecutorService executorService;
    private int time;
    private TimeUnit timeUnit;
    private BlockingQueue<String> queue = new LinkedBlockingQueue<String>(500);

    public EverlastingThread(ScheduledExecutorService executorService, int time, TimeUnit timeUnit) {
        this.executorService = executorService;
        this.time = time;
        this.timeUnit = timeUnit;
    }

    public void run() {

        // call the service. if Service returns any data put it an the queue
        queue.add("task");
    }

    public void callService() throws Exception {
        // while queue has …
Run Code Online (Sandbox Code Playgroud)

java scheduled-tasks executor

9
推荐指数
1
解决办法
6335
查看次数

我怎么用番石榴做这个?

有没有办法使用番石榴实现以下目标?

//anything better than using Files.append() in a loop?
org.apache.commons.io.FileUtils.writeLines(File file, Collection lines, String lineEnding);

//gives a byte[] that is fed to Files.write(byte[] from, File to)
org.apache.commons.lang.SerializationUtils.serialize(Serializable obj) 

//get an object from a byte[] 
SerializationUtils.SerializationUtils.deserialize(byte[] from)
Run Code Online (Sandbox Code Playgroud)

谢谢.

java apache-commons guava

7
推荐指数
1
解决办法
5400
查看次数

如何使用Guavas Splitter并保留分隔符(没有正则表达式)?

有没有一种简单的方法可以使用Guavas Splitter来分割字符串并保留分隔符而不使用正则表达式?

就像是

String string = "1+2-3*40";
Splitter splitter = Splitter.on(CharMatcher.DIGIT.negate()).retainDelimiters();
Run Code Online (Sandbox Code Playgroud)

这给了

[1, +, 2, -, 3, *, 40]
Run Code Online (Sandbox Code Playgroud)

我知道Splitter.onpattern(),但这需要我给它一个正则表达式(但这就是我想要避免的).

java split guava

5
推荐指数
1
解决办法
740
查看次数

正则表达式匹配一个后跟空格的数字

我希望使用reg-ex来分割以下字符串

1 hi my name is John. 2 I live at house 32. 3 I see stars.
Run Code Online (Sandbox Code Playgroud)

[hi my name is John,  I live at house 32. , I see stars]
Run Code Online (Sandbox Code Playgroud)

请注意,我试图拆分数字后跟空格

java regex

3
推荐指数
1
解决办法
2万
查看次数

如何在 Java 中交换 arrayMap 值和键

我在反转给定的映射并将其反转的键和值存储到另一个映射中时遇到了一些麻烦。我有一个方法原型如下:

public static Map<String, Set<String>> reverse (Map <String, Set<String>> graph);
Run Code Online (Sandbox Code Playgroud)

因此,如果我有有向图的示例键,则:

{c -> arraySet{f, e}}
{b -> d}
{a -> arraySet{c, b}} 
{d -> g}
{e -> d}
{f -> arraySet{g, d}}
Run Code Online (Sandbox Code Playgroud)

我需要有效地反转这个图,以便我有 d -> b 而不是 b -> d。

我认为这对我来说只是交换原始图中的值和键并将它们添加到 reverseMap 中。我想我可以遍历图中给定键的每组值,然后将它们存储在列表中。

不幸的是,我在实施和考虑它时遇到了麻烦。我真的很感激朝正确方向的推动。

java map key-value

2
推荐指数
1
解决办法
2288
查看次数

org.springframework.transaction.annotation.Transactional vs javax.jdo.annotations.Transactional

@Transcational在服务层使用spring 时,我需要放上<annotation driven>xml文件.

我想知道

  1. 可以javax.jdo.annotations.Transactional将在服务层使用就像春天呢?无需配置xml文件.等等?

  2. 可以javax.jdo.annotations.Transactional在服务层上使用,无论我是否在dao层使用hibernate/jpa/jdo?除了标记方法之外,我还需要配置其他任何东西@Transactional吗?

  3. javax.jdo.annotations.Transactional和之间是否有任何差异/限制org.springframework.transaction.annotation.Transactional

java spring jdo

1
推荐指数
1
解决办法
2919
查看次数

迭代Collection <List <Integer >>

我使用Guava库来生成整数的排列1,2并且3.

Collection<List<Integer>> vehCombinations = Collections2.orderedPermutations(vehicles);
Run Code Online (Sandbox Code Playgroud)

接下来,我需要迭代vehCombinations并检查关于某些约束的每个排列:

for (int j=0; j<vehCombinations.size(); j++)
{
  List<Integer> veh = vehCombinations.get(i);
}
Run Code Online (Sandbox Code Playgroud)

vehCombinations.get(i) 不被允许.

那么,我如何从中提取排列vehCombinations

java collections guava

1
推荐指数
1
解决办法
1515
查看次数

如何处理shell脚本中的引号

这个问题我能够获得oracle jdk的wget url.我打算在脚本vis中使用它

wget_opts="-c --no-check-certificate --no-cookies --header --load-cookies="Cookie: oraclelicense=accept-securebackup-cookie""
jdk_download_url="http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"

/usr/bin/wget $wget_opts $jdk_download_url
Run Code Online (Sandbox Code Playgroud)

当我回显上面的命令时,它显示正常,并能够正确下载该文件.但是在脚本中运行命令时,我得到了以下内容

--2014-06-04 14:19:43--  http://oraclelicense=accept-securebackup-cookie%22/
Resolving oraclelicense=accept-securebackup-cookie"... failed: Name or service not known.
wget: unable to resolve host address “oraclelicense=accept-securebackup-cookie"”
--2014-06-04 14:20:03--  http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz
Resolving download.oracle.com...
Run Code Online (Sandbox Code Playgroud)

Wget获取错误的URL.

我该如何纠正?

linux shell

1
推荐指数
1
解决办法
332
查看次数