小编som*_*rti的帖子

两个线程同时执行同步块

下面是Thread进入同步块的代码,等待5秒然后退出.我已经Thread同时启动了两个实例.

期望是其中一个线程将拥有对同步对象的锁定,而另一个将等待.5秒后,当锁拥有者退出时,等待线程将执行.

但是,实际上,两个线程同时执行同步块并同时退出.

预期产出:

Thread-X <timeX> received the lock.
Thread-X <timeX+5s> exiting...
Thread-Y <timeY> received the lock.
Thread-Y <timeY+5s> exiting...
Run Code Online (Sandbox Code Playgroud)

实际产量:

Thread-X <time> received the lock.
Thread-Y <time> received the lock.
Thread-X <time+5s> exiting...
Thread-Y <time+5s> exiting...
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?

import java.text.SimpleDateFormat;
import java.util.Date;

public class Test2 {
public static void main(String[] args) {
    MyRunnable m = new MyRunnable();
    Thread t = new Thread(m);
    Thread t1 = new Thread(m);
    t.start();
    t1.start();
    }
}

class MyRunnable implements Runnable { …
Run Code Online (Sandbox Code Playgroud)

java multithreading synchronized thread-synchronization

47
推荐指数
3
解决办法
3091
查看次数

安装错误:ftheader.h:没有这样的文件或目录

当我尝试构建matplotlib-1.3.1时,我得到以下freetype头错误.可能它找不到ftheader.h.有关如何解决这个问题的任何想法?

注意:我刚刚按照FreeType安装中提到的说明安装了Freetype- 2.5.0.1,因为从源代码手动构建Matplotlib-1.3.1失败了,因为最初找不到所需的软件包'freetype'.

In file included from src/ft2font.h:16,
             from src/ft2font.cpp:3:
/usr/include/ft2build.h:56:38: error: freetype/config/ftheader.h: No such file or directory
In file included from src/ft2font.cpp:3:
src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:20:10: error: #include expects "FILENAME" or <FILENAME>
src/ft2font.h:21:10: error: #include expects "FILENAME" or <FILENAME>
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h:69,
             from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/char_traits.h:41,
             from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/string:42,
             from ./CXX/Python2/Exception.hxx:46,
             from ./CXX/Exception.hxx:40,
             from ./CXX/Python2/Objects.hxx:44,
             from ./CXX/Python2/Extensions.hxx:52,
             from ./CXX/Extensions.hxx:40,
             from …
Run Code Online (Sandbox Code Playgroud)

numpy matplotlib freetype hortonworks-data-platform

12
推荐指数
2
解决办法
7917
查看次数

Matplotlib.Pyplot不显示输出; 没有错误

我的平台如下

Centos 6.x(在Win-7主机上运行的VirtualBox VM),Python 2.6.6,Matplotlib 1.3.1,Numpy 1.8.0,Scipy 0.14.0.dev-bb608ba

我正在运行以下histogram.py代码

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt

mu, sigma = 0, 1 # mean and standard deviation
f = np.random.normal(mu, sigma, 1000) # generate feature-vector with normal distribution

# plot the histogram - check the distribution
count, bins, ignored = plt.hist(f, 30, normed=True)

plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
                np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
        linewidth=2, color='r')
plt.xlabel('Values')
plt.ylabel('Probability')
plt.title('Histogram')
plt.text(60, .025, r'$\mu=0,\ …
Run Code Online (Sandbox Code Playgroud)

python numpy matplotlib scipy

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

缺少 Hive 执行 Jar:/usr/local/hadoop/hive/lib/hive-exec-*.jar

我在我的 Ubuntu 机器上设置的单节点集群上运行 Hadoop 1.0.4。

我做了以下步骤来下载和安装 hive 版本

> svn co http://svn.apache.org/repos/asf/hive/trunk hive    
> cd hive
Run Code Online (Sandbox Code Playgroud)

我的 hadoop 安装文件夹是 $HADOOP_HOME/hive 和 $HADOOP_HOME=/usr/local/hadoop。我在 /home/hduser 下的 .bashrc 中设置了环境变量,这是我的 Hadoop 用户和 $JAVA_HOME。

export HADOOP_HOME=/usr/local/hadoop

export HIVE_HOME=$HADOOP_HOME/hive

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
Run Code Online (Sandbox Code Playgroud)

我还在 $PATH 变量中添加了 hadoop 和 hive 的 bin 文件夹,如下所示

export PATH=$PATH:$HADOOP_HOME/bin    
export PATH=$HIVE_HOME/bin:$PATH
Run Code Online (Sandbox Code Playgroud)

但是在从 CLI 运行 hive 时,我收到以下错误。

hduser@somnath-laptop:/usr/local/hadoop/hive$ bin/hive    
Missing Hive Execution Jar: /usr/local/hadoop/hive/lib/hive-exec-*.jar
Run Code Online (Sandbox Code Playgroud)

我应该下载这个 jar 并将其添加到 /lib/ 中,还是需要配置一些特定于 hive 的环境变量。任何建议都会非常有帮助。

hadoop hive jar environment-variables

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

嵌套异常是java.lang.IllegalArgumentException:不是托管类型:class

我想部署一个Spring-Boot application具有Service访问JpaRepository它连接到PostgreSQL DB在系统运行时JPAHibernate中,指的连接属性src/main/resources/application.properties

当我在Tomcat上部署构建的.WAR时,应用程序无法启动错误日志中给出的错误.

有人可以帮忙解决这个错误的含义吗?

注意:我已经注意到了麻烦点MyServiceImplMyRequestBody类,但我没有得到该错误的确切原因,因为我是新来的Spring框架.

我的Spring Boot Starter项目中相关类的定义如下:

Spring Boot应用程序

@SpringBootApplication
@ComponentScan(<root package name under which all subpackages containing relevant classes >)
public class MySpringBootApplication extends SpringBootServletInitializer {
Run Code Online (Sandbox Code Playgroud)

我的Spring-Boot RestController类(自动装配MyService类实例)

@RestController
public class MyController {

    @Autowired
    MyService myService;
Run Code Online (Sandbox Code Playgroud)

我的服务界面(我没有提供任何@Service注释)

public interface MyService {
    //all service method definitions
}
Run Code Online (Sandbox Code Playgroud)

Spring ServiceImpl类,具有在PostgreSQL DB上运行的自动装配存储库实例

@Service("myService")
public class MyServiceImpl implements MyService {

       @Autowired
       private MyRepository …
Run Code Online (Sandbox Code Playgroud)

spring spring-data spring-data-jpa spring-boot spring-restcontroller

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

将HashMap Key Iterator转换为List Iterator

我需要访问HashMap关键元素,就像使用prev和curr指针进行一些比较的链表一样.我将HashMap Key Iterator类型化为List Iterator来访问当前和以前的关键元素.下面是代码

HashMap<Node,Double> adj;
ListIterator<Node> li = (ListIterator<Node>) adj.keySet().iterator();

while (li.hasNext()) {
    if (li.hasPrevious()) {
                prev = li.previous();
    } else {
                prev = null;
    }
...
}
Run Code Online (Sandbox Code Playgroud)

但我得到以下例外

Exception in thread "main" java.lang.ClassCastException: java.util.HashMap$KeyIterator cannot be cast to java.util.ListIterator
at Types$AdjList.makeConnected(Types.java:357)
at Main.main(Main.java:89)
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以将HashMap Key Iterator强制转换为List Iterator来解决我的目的.任何帮助将不胜感激.

谢谢,

索姆纳特

java collections

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

JPG Image没有出现在动态Web项目的JSP中

我试图在Eclipse Indigo IDE中创建的动态Web项目中使用以下index.jsp文件中的图像.我在我的项目文件夹的WebContent下的WEB-INF/images/pict1.jpg下添加了图像.但是当我在浏览器中运行时,图像不可见.文本和提交按钮按预期进行.我错过了什么吗?有关如何制作图像的任何想法?

任何帮助将不胜感激.下面是代码.

谢谢,

索姆纳特

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
Run Code Online (Sandbox Code Playgroud)

<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<c:import url="/WEB-INF/javascript/index.js" />

<title>My Page</title>
</head>
<body>
<img alt="picture1" src="images/pict1.jpg">
<table border="0">
<tr><td valign="top">
<h1>Continue</h1></td><td><input type="submit"></td></tr>
<tr><td valign="top">
<h1>Continue</h1></td><td><input type="submit"></td></tr>
</table>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript eclipse jsp

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

将object [] []转换为ArrayList <Object []>

我想可能在我的帖子之前已经多次询问/回答了这个问题.但我无法得到我想要的东西,所以我再次发布:

我想这样做:

float[][] fa2 = {{7,2}, {5,4}, {9,6}, {4,7}, {8,1}, {2,3}};
ArrayList<Float[]> AF = new ArrayList<Float[]>();
AF = Arrays.asList(fa2);
Run Code Online (Sandbox Code Playgroud)

但它给出了一个错误:

Type mismatch: cannot convert from List<float[]> to ArrayList<Float[]>
Run Code Online (Sandbox Code Playgroud)

我理解错误的原因但是在Java中进行转换的最方便的方法是什么?

这是我能想到的最简单的方法.有更好/更方便的东西吗?

float[][] fa2 = {{7,2}, {5,4}, {9,6}, {4,7}, {8,1}, {2,3}};
ArrayList<Float[]> AF = new ArrayList<Float[]>(fa2.length);
for (float[] fa : fa2) {
    //initialize Float[]
    Float[] Fa = new Float[fa.length];
    //copy element of float[] to Float[]
    int i = 0;
    for (float f : fa) {
        Fa[i++] = Float.valueOf(f);
    }
    //add Float[] element …
Run Code Online (Sandbox Code Playgroud)

java arrays collections arraylist multidimensional-array

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

org.apache.kafka.common.KafkaException:无法构造kafka使用者

我手动启动Zookeeper,然后启动Kafka服务器,最后启动Kafka-Rest服务器及其相应的属性文件。接下来,我将我的Spring Boot应用程序部署在tomcat上

在Tomcat日志跟踪中,出现错误org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.KafkaException: Failed to construct kafka consumer,我的应用程序无法启动

错误记录

25-Dec-2017 15:00:32.508 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring-kafka-webhook-service-0.0.1-SNAPSHOT]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) …
Run Code Online (Sandbox Code Playgroud)

apache-kafka spring-boot kafka-consumer-api spring-kafka

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

maven archetype:生成org.apache.maven.plugin.MojoFailureException导致的失败

我已经安装了maven 2并按照以下链接中提到的教程进行操作

maven.apache.org/guides/getting-started/maven-in-five-minutes.html

但是在执行archetype:generate命令时,

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

[INFO] Trace
org.apache.maven.BuildFailureException: Error merging velocity templates
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoFailureException: Error merging velocity templates
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:211)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Run Code Online (Sandbox Code Playgroud)

有关信息,

我正在使用Sun OpenJDK 1.6.0,Maven 2和Xubuntu平台.

任何有关上述错误的暗示性帮助将不胜感激.

谢谢,

索姆纳特

ubuntu maven-2 maven-plugin maven-3 maven

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