我正在开发一个多线程程序,其中我试图确保每个线程都在运行30 minutes。假设如果我们有10 threads那么每个线程都10应该运行30 minutes。
下面是我的代码-
class ThreadTask implements Runnable {
private final long endTime;
public ThreadTask(long endTime) {
this.endTime = endTime;
}
@Override
public void run() {
while (System.currentTimeMillis() <= endTime) {
// do something meaningful
}
}
}
public class TestPool {
public static void main(String[] args) {
// create thread pool with given size
ExecutorService service = Executors.newFixedThreadPool(1000);
long startTime = System.currentTimeMillis();
long endTime = startTime + (30 * 60 …Run Code Online (Sandbox Code Playgroud) 我想取两列的平均值并在新列中显示,如下所示:
+-+--+--+--+--------+--------+
|A|B |C |D |AVG(B/C)|AVG(C/B)|
+-+--+--+--+--------+--------+
|S|23|34|56| | |
+-+--+--+--+--------+--------+
|T|45|6 |79| | |
+-+--+--+--+--------+--------+
Run Code Online (Sandbox Code Playgroud)
因此,如上所示,我需要获取每行值并执行 B/C,然后相应地取平均值以将其显示在新列中。
我想在 SQL 查询中执行此操作。是否可以在 SQL 命令中执行此操作?我知道该AVG()函数确实取一列的平均值,但我该怎么做B/C然后取平均值呢?另外,如果我还需要取 B 和 C 的平均值,我该怎么做。
这就是我现在正在做的事情:
Select A,B,C,D FROM tableTest where A='S';
Run Code Online (Sandbox Code Playgroud)
我现在必须取相应的平均值,并且在查询中另外添加两列来显示相应的结果。
我在我的代码中使用Java Callable Future.下面是我使用未来和callables的主要代码 -
下面是我使用未来和callables的主要代码 -
public class TimeoutThread {
public static void main(String[] args) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(5);
Future<String> future = executor.submit(new Task());
try {
System.out.println(future.get(3, TimeUnit.SECONDS));
} catch (TimeoutException e) {
}
executor.shutdownNow();
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的Task类,它实现了Callable接口,我在其中使用REST来调用我的SERVERS RestTemplate.然后使用反序列化JSON字符串GSON.
class Task implements Callable<String> {
private static RestTemplate restTemplate = new RestTemplate();
@Override
public String call() throws Exception {
String url = "some_url";
String response = restTemplate.getForObject(url, String.class);
TestResponse jsonResponse = new Gson().fromJson(response, …Run Code Online (Sandbox Code Playgroud) 我试图avro二进制编码我的JSON字符串.下面是我的JSON字符串,我创建了一个简单的方法来进行转换,但我不确定我的方式是否正确?
public static void main(String args[]) throws Exception{
try{
Schema schema = new Parser().parse((TestExample.class.getResourceAsStream("/3233.avsc")));
String json="{"+
" \"location\" : {"+
" \"devices\":["+
" {"+
" \"did\":\"9abd09-439bcd-629a8f\","+
" \"dt\":\"browser\","+
" \"usl\":{"+
" \"pos\":{"+
" \"source\":\"GPS\","+
" \"lat\":90.0,"+
" \"long\":101.0,"+
" \"acc\":100"+
" },"+
" \"addSource\":\"LL\","+
" \"add\":["+
" {"+
" \"val\":\"2123\","+
" \"type\" : \"NUM\""+
" },"+
" {"+
" \"val\":\"Harris ST\","+
" \"type\" : \"ST\""+
" }"+
" ],"+
" \"ei\":{"+
" \"ibm\":true,"+
" \"sr\":10,"+
" \"ienz\":true,"+
" \"enz\":100,"+
" …Run Code Online (Sandbox Code Playgroud) 如果我有类似下面的东西,那么这意味着什么 synchronized block
synchronised (syncObject) {
Run Code Online (Sandbox Code Playgroud)
基本上,它意味着只有一个线程可以在上面的块中,并且一旦一个线程完成执行,第二个线程将进入同步块同步(syncObject).对?任何人都可以用LayMan语言向我解释,这样我可以获得更好的画面吗?
private static final class Task implements Runnable {
{
private static Object syncObject = new Object();
public Task(Command command, BlockingQueue<Integer> pool1, BlockingQueue<Integer> pool2) {
this.command = command;
this.existPool = pool1;
this.newPool = pool2;
}
public void run()
{
synchronised (syncObject) {
if() {
existId = existPool.take();
attributeMethod(existId);
} else if() {
newId = newPool.take();
attributeMethod(newId);
}
}
}
}
// So I need to make this method synchronized or not? Currently …Run Code Online (Sandbox Code Playgroud) 问题陈述:-
我得到以下异常 -
org.apache.hadoop.hdfs.protocol.DSQuotaExceededException:
org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: The DiskSpace
quota of /tmp is exceeded: quota=659706976665600 diskspace consumed=614400.1g
Run Code Online (Sandbox Code Playgroud)
所以我只是想知道目前/ tmp目录的大小是多少,因此我得到了这个例外.如何查看/ tmp中的可用空间?
更新: -
bash-3.00$ df -h /tmp
Filesystem size used avail capacity Mounted on
rpool/tmp 10G 2.2G 7.8G 22% /tmp
Run Code Online (Sandbox Code Playgroud)
我现在很困惑为什么我得到那个例外,因为它清楚地说明我有空间可用.
我从早上开始挖掘所有的jetbrains教程和谷歌搜索,如果有的话,我会看到在我的intelliJ IDEA IDE 12.x版本中将ctrl替换为meta的方式或意义,但令人惊讶的是,没有找到快捷方式或解释直到时间我的通知.这里的任何人都知道我如何解释"元"键盘快捷方式,以使我的intelliJ快捷方式工作.请参阅下面的屏幕截图和指南,我如何在Windows中解释?
设置键盘图会有帮助吗?如果是的话我该怎么办呢!

任何帮助将非常感激.我在Idea 12.1.4上使用Windows
谢谢!
我正在开发一个项目,其中我有多个接口和两个实现类,需要实现这两个接口.
假设我的第一个接口是 -
public Interface interfaceA {
public String abc() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
它的实施是 -
public class TestA implements interfaceA {
// abc method
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它 -
TestA testA = new TestA();
testA.abc();
Run Code Online (Sandbox Code Playgroud)
现在我的第二个界面是 -
public Interface interfaceB {
public String xyz() throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
它的实施是 -
public class TestB implements interfaceB {
// xyz method
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它 -
TestB testB = new TestB();
testB.xyz();
Run Code Online (Sandbox Code Playgroud)
问题陈述:-
现在我的问题是 - 有什么办法,我可以并行执行这两个实现类吗?我不想按顺序运行它.
意思是,我想并行运行TestA和TestB实现?这可能吗?
java parallel-processing multithreading callable executorservice
假设给你一个未排序整数数组:
A = {3,4,5,1,4,2}
Run Code Online (Sandbox Code Playgroud)
输入6
输出 :{5,1}, {4,2}
我怎样才能在 O(n) 或 O(log n) 内做到这一点。任何建议将不胜感激。
更新: 我们可以写一些比这更有效的东西吗?
for(int i=0;i<array.length-1;i++)
{
if(array[i]+array[i+1]==6)
System.out.println("{"+array[i]+","+array[i+1]+"}");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我们拥有的一些旧遗留代码编写junit
下面是DataLogger类中的方法,我正在编写junit并且我正在使用jmockit -
private Object[] extractMessageObjects(final Object... objects) {
Object[] result = new Object[objects.length - 1];
System.arraycopy(objects, 0, result, 0, result.length);
return result;
}
Run Code Online (Sandbox Code Playgroud)
所以下面的测试应该可行.对?
@Test
public void testLogDebugWithStackTrace() {
DataLogger logger = DataLogger.getInstance(ClientTest.class);
Object obj[] = new Object[] {1};
Deencapsulation.invoke(logger, "extractMessageObjects", obj);
}
Run Code Online (Sandbox Code Playgroud)
但我得到例外 -
No compatible method found: extractMessageObjects(java.lang.Integer)
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?