我只是在探索java.util.concurrent包.
我了解到类' Future '有一个方法boolean cancel(boolean mayInterruptIfRunning)
请查找附上我写的测试代码:
package com.java.util.concurrent;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
public class FutureTester {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
int poolCnt = 1;
Callable<NumberPrinter> numberPrinter = null;
ScheduledThreadPoolExecutor schPool = new ScheduledThreadPoolExecutor(
poolCnt);
ScheduledFuture<NumberPrinter>[] numPrinterFutures = new ScheduledFuture[poolCnt];
FutureTask<NumberPrinter>[] futureTask = new FutureTask[poolCnt];
for (int i = 0; i < poolCnt; i++) {
numberPrinter = new …
Run Code Online (Sandbox Code Playgroud) 我因某些愚蠢的错误而陷入困境但却无法弄明白!
Hibernate 4.2.6
我之前曾多次提到这个问题,例如这里
的hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<mapping resource="Event.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
Event.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.db.pojo.Event" table="Events">
<id name="id" column="Id">
<generator class="native"></generator>
</id>
<property name="title" column="Title"></property>
<property name="date" column="Date" type="timestamp"></property>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
的HibernateUtil
package com.db.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil { …
Run Code Online (Sandbox Code Playgroud) 我希望导入,更改,重建,测试和推送/签入我对此Github存储库中可用代码的更改
目前,我不希望为此目的使用任何IDE或插件.
我在我的Windows机器上安装了Maven,按照安装说明进行操作,如下所示:
C:\Documents and Settings\298790\My Documents\Downloads\seismichadoop-master>mvn
-X package
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:
28+0530)
Maven home: D:\Omkar\Development\Softwares\Tools\apache-maven-3.0.5
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_20\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from D:\Omkar\Development\Softwares\Tools\apache
-maven-3.0.5\conf\settings.xml
[DEBUG] Reading user settings from C:\Documents and Settings\298790\.m2\settings
.xml
[DEBUG] Using local repository at C:\Documents and Settings\298790\.m2\repositor
y
[DEBUG] …
Run Code Online (Sandbox Code Playgroud) 我正在使用Jersey 2.3
我的WS端点类:
@Path("/employees")
public class EmployeeWSEndpoint {
@Context
Request request;
@GET
@Path("/allEmployees")
@Produces(MediaType.APPLICATION_JSON)
public List<Employee> getAllEmployees() {
System.out.println("In EmployeeWSEndpoint.getAllEmployees()");
EmployeeService employeeService = new EmployeeServiceImpl();
return employeeService.getAllEmployees();
}
@GET
@Path("/allDept")
@Produces(MediaType.APPLICATION_JSON)
public List<String> getAllDept() {
System.out.println("In EmployeeWSEndpoint.getAllDept()");
List<String> deptNames = new ArrayList<>();
deptNames.add("CoE");
deptNames.add("iLabs");
return deptNames;
}
@GET
@Path("/allDeptPOJO")
@Produces(MediaType.APPLICATION_JSON)
public TempPOJO getAllDeptPOJO() {
System.out.println("In EmployeeWSEndpoint.getAllDeptPOJO");
TempPOJO tempPOJO = new TempPOJO();
return tempPOJO;
}
}
Run Code Online (Sandbox Code Playgroud)
员工POJO:
public class Employee {
private int id;
private String firstName;
private String middleName; …
Run Code Online (Sandbox Code Playgroud) 我在MySQL中有一个表.nas_comps.
select comp_code, count(leg_id) from nas_comps_01012011_31012011 n group by comp_code;
comp_code count(leg_id)
'J' 20640
'Y' 39680
Run Code Online (Sandbox Code Playgroud)
首先,我使用Sqoop将数据导入HDFSHadoop版本1.0.2):
sqoop import --connect jdbc:mysql://172.25.37.135/pros_olap2 \
--username hadoopranch \
--password hadoopranch \
--query "select * from nas_comps where dep_date between '2011-01-01' and '2011-01-10' AND \$CONDITIONS" \
-m 1 \
--target-dir /pros/olap2/dataimports/nas_comps
Run Code Online (Sandbox Code Playgroud)
然后,我创建了一个外部的分区Hive表:
/*shows the partitions on 'describe' but not 'show partitions'*/
create external table nas_comps(DS_NAME string,DEP_DATE string,
CRR_CODE string,FLIGHT_NO string,ORGN string,
DSTN string,PHYSICAL_CAP int,ADJUSTED_CAP int,
CLOSED_CAP int)
PARTITIONED BY (LEG_ID int, month INT, COMP_CODE …
Run Code Online (Sandbox Code Playgroud) 我正在执行MR over HBase.
reducer中的业务逻辑大量访问两个表,比如T1(40k行)和T2(90k行).目前,我正在执行以下步骤:
1.在reducer类的构造函数中,执行以下操作:
HBaseCRUD hbaseCRUD = new HBaseCRUD();
HTableInterface t1= hbaseCRUD.getTable("T1",
"CF1", null, "C1", "C2");
HTableInterface t2= hbaseCRUD.getTable("T2",
"CF1", null, "C1", "C2");
Run Code Online (Sandbox Code Playgroud)
在减少(...)
String lowercase = ....;
/* Start : HBase code */
/*
* TRY using get(...) on the table rather than a
* Scan!
*/
Scan scan = new Scan();
scan.setStartRow(lowercase.getBytes());
scan.setStopRow(lowercase.getBytes());
/*scan will return a single row*/
ResultScanner resultScanner = t1.getScanner(scan);
for (Result result : resultScanner) {
/*business logic*/
}
Run Code Online (Sandbox Code Playgroud)
虽然不确定上面的代码是否在第一时间是合理的,但我有一个问题 - 获得(...)会在扫描中提供任何性能优势吗?
Get get …
Run Code Online (Sandbox Code Playgroud) 我开始要求从远程Ubuntu机器上的目录中读取和写入文件.
首先,我编写了一个Java程序,可以从远程Windows机器(即LAN)上的共享文件夹中读取,写入文件.在这里,这样的东西适用于我的(本地)Windows机器:
File inputFile = new File(
"\\172.17.89.76\EBook PDF");/*ignore the syntax errors, the loc is just for the idea*/
Run Code Online (Sandbox Code Playgroud)
现在,当我考虑一台远程Ubuntu机器时,显然我不能做这样的事情,因为机器不在局域网上(我不确定即使它在LAN上也能做到!).因此,我尝试了以下方法:
在做所有这些的时候,我有很多疑问,阅读过很多帖子等等,我觉得我在基础知识上缺少一些东西:
重申一下,我想用Java I/O编写一个代码(普通的或者nio,两者都很好),这些代码只需读取,编写远程文件而不使用ftp,http等协议或套接字发送器 - 接收器模型的服务.我的期望有效吗?
PS:如果我需要精心准确地提出我的问题,请发表评论!
注意:几个小时前,我开始使用 HBase 并且我来自 RDBMS 背景:P
我有一个类似 RDBMS 的表 CUSTOMERS 具有以下列:
我想到了以下 HBase 等效项:
表:客户行键:客户 ID
列族:CUSTOMER_INFO
列:姓名电子邮件地址移动
从我读过的内容来看,RDBMS 表中的主键大致类似于HBase 表的行键。因此,我想保留 CUSTOMER_ID 作为行键。
我的问题既愚蠢又直接:
* * *编辑添加示例代码片段
我只是想在 shell 中使用“put”为客户表创建一行。我这样做了:
hbase(main):011:0> put 'CUSTOMERS', 'CUSTID12345', 'CUSTOMER_INFO:NAME','Omkar Joshi'
0 row(s) in …
Run Code Online (Sandbox Code Playgroud) 请考虑附图中所示的场景:
请指导一下.
在Petter回答后添加更多细节:
现在,最重要的部分 - 问题:
我有一个聚合查询如下:
db.TWITTER_DATA_Processed.aggregate( {$match : { SpId : 840, Scheduler_id : "SCH_01" }},{$group : {_id : {SpId : "$SpId", Scheduler_id : "$Scheduler_id",Country : "$Country"}, positive_count : { $sum: { $cond: [ { $gt: [ "$Sentiment", 0 ] } , 1, 0 ] } }, neutral_count : { $sum: { $cond: [ { $eq: [ "$Sentiment", 0 ] } , 1, 0 ] } }, negative_count : { $sum: { $cond: [ { $lt: [ "$Sentiment", 0 ] } , 1, 0 …
Run Code Online (Sandbox Code Playgroud)