帮助处理 Java 程序的多核。
我是否正确理解当使用类Thread和接口时Runnable,如果有其他内核,Java 程序将仅在一个 CPU 内核上使用多线程?
而要实现Java程序的多核处理,是否需要使用专门的Java类,例如Fork/Join Framework?
帮助处理 Java 程序的多核。
我是否正确理解当使用类Thread和接口时Runnable,如果有其他内核,Java 程序将仅在一个 CPU 内核上使用多线程?
而要实现Java程序的多核处理,是否需要使用专门的Java类,例如Fork/Join Framework?
我不知道如何检查多路复用的操作,以及是否在执行期间。
我向 curl_multi_exec() 添加了4 个 curl_init ( )描述符,它们执行对一个域的请求。在CURLOPT_VERBOSE日志中,在第一个描述符的每个后续中,我看到以下行:
* Found bundle for host yandex.ru: 0x55adc86744f0 [serially]
更多细节。
例子:
// создаем дескриптор cURL
$ch1 = curl_init();
// устанавливаем опции
curl_setopt($ch1, CURLOPT_URL, "https://yandex.ru");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_FILE, $curl1_exec);
curl_setopt($ch1, CURLOPT_STDERR, $curl1_log);
curl_setopt($ch1, CURLOPT_VERBOSE, 1);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch1, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
// создаем новый дескриптор копированием существующего
$ch2 = curl_copy_handle($ch1);
// устанавливаем новые опции
curl_setopt($ch2, CURLOPT_URL, "https://yandex.ru/all");
curl_setopt($ch2, CURLOPT_FILE, $curl2_exec);
curl_setopt($ch2, CURLOPT_STDERR, $curl2_log);
// создаем новый дескриптор копированием существующего
$ch3 = curl_copy_handle($ch1);
// устанавливаем новые опции
curl_setopt($ch3, CURLOPT_URL, "https://yandex.ru/news/");
curl_setopt($ch3, CURLOPT_FILE, $curl3_exec);
curl_setopt($ch3, CURLOPT_STDERR, $curl3_log);
// создаем новый дескриптор копированием существующего
$ch4 = curl_copy_handle($ch1);
// устанавливаем новые опции
curl_setopt($ch4, CURLOPT_URL, "https://yandex.ru/images/?from=tabbar");
curl_setopt($ch4, CURLOPT_FILE, $curl4_exec);
curl_setopt($ch4, CURLOPT_STDERR, $curl4_log);
//создаем набор дескрипторов cURL
$mh = curl_multi_init();
//добавляем дескрипторы
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
curl_multi_add_handle($mh, $ch3);
curl_multi_add_handle($mh, $ch4);
//добавляем попытку использовать мультиплексирование, если это возможно
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
//запускаем множественный обработчик
do {
$status = curl_multi_exec($mh, $active);
if ($active) {
// Ждем какое-то время для оживления активности
curl_multi_select($mh);
}
} while ($active && $status == CURLM_OK);
//закрываем дескрипторы
curl_multi_close($mh);
连接信息。
第一的:
* Rebuilt URL to: https://yandex.ru/
* Hostname 'yandex.ru' was found in DNS cache
* Trying 77.88.55.60...
* TCP_NODELAY set
* Connected to yandex.ru (77.88.55.60) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=yandex.ru; O=Yandex LLC; OU=ITO; L=Moscow; ST=Russia; C=RU
* start date: Sep 5 11:12:34 2019 GMT
* expire date: Sep 4 11:12:34 2020 GMT
* subjectAltName: host "yandex.ru" matched cert's "yandex.ru"
* issuer: C=RU; O=Yandex LLC; OU=Yandex Certification Authority; CN=Yandex CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x556999495740)
> GET / HTTP/2
Host: yandex.ru
Accept: */*
第二:
* Found bundle for host yandex.ru: 0x5569994ce320 [serially]
* Server doesn't support multi-use (yet)
* Hostname 'yandex.ru' was found in DNS cache
* Trying 77.88.55.60...
* TCP_NODELAY set
* Connected to yandex.ru (77.88.55.60) port 443 (#1)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=yandex.ru; O=Yandex LLC; OU=ITO; L=Moscow; ST=Russia; C=RU
* start date: Sep 5 11:12:34 2019 GMT
* expire date: Sep 4 11:12:34 2020 GMT
* subjectAltName: host "yandex.ru" matched cert's "yandex.ru"
* issuer: C=RU; O=Yandex LLC; OU=Yandex Certification Authority; CN=Yandex CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55699949ea40)
> GET /all HTTP/2
Host: yandex.ru
Accept: */*
phpStorm 是否能够像“YUI Compressor JS”/CSS 插件一样自动缩小 HTML 文件?
问题是,如果不进行最小化,HTML 文件会更大,文件中的换行会影响页面在浏览器中的显示。
我不明白是否有技术允许您为浏览器编写 2D 游戏“帝国时代 2”的模拟?(在任何合适的地方建造建筑物,开采资源,指挥军队,指挥军队,战斗等)在什么技术上可以创造这样的游戏?据我了解,html5 + javascript + css 技术不允许这样做。我发现的一切都很原始。
据我了解,Flash-games是否适合执行此类游戏?
此外,Unity 可以导出游戏以在浏览器中运行,但到目前为止我还无法理解此类游戏的限制是什么。
总的来说,我想了解如何更好地编写这样一个游戏,以便它可以在浏览器中播放。谢谢!
数据库有2个表:
|------Отдел-----|
| ИД Отдела |
| Наименование |
| .... |
|----------------|
|----Сотрудник---|
| ИД Сотрудника |
| ФИО |
| ИД Отдела (FK) |
| .... |
|----------------|
问题是,如何使用 Hibernate 选择所有部门以及每个部门的员工人数?我以前的版本按部门选择了所有部门和所有员工,但同时拉取了员工的所有数据,这不是很理想,因为。你需要一些。当然,我可以使用.size(). 但我不想让 Hibernate 承担不必要的工作,也不想强迫它拖累员工的所有信息。
告诉我如何正确实施?
我真的需要建议。我正在创建几个类对象MyClass。
public class MyClass {
enable(Params params) {
// Логика. Выполнение, которой зависит от содержания переменной `params`
}
}
接下来,我需要为每个对象运行一个方法,enable(Params params)同时将类的不同实现传递给每个方法Params。那些。params每种方法的对象字段集enable(Params params)将不同。我这样做是为了根据传递的参数组织方法的灵活执行。
我将类的实例存储MyClass在数据库中。
实际上是一个问题。如何Params在数据库中存储类的实例。这样我就可以转向数据库并MyClass使用自己独特的参数启动类实例?难点是建Params一张表存对象是行不通的,因为 实现对象的字段Params会有所不同。
在这种情况下,我看到了一个选项——将对象的序列化保存在数据库中Params。帮助提供有关如何在这种情况下正确组织数据存储的建议。
(我使用 Spring 和 Hibernate。也许我缺少针对此类问题的开箱即用的解决方案)谢谢!
求助指教。我正在 Spring Boot 上创建一个将处理大量数据的应用程序,而此处理的效率很重要。
例如:
50 个表,每个表都有一些商品/服务的价格。表中的条目从 5000 个开始。每个表都是一个单独的商品和服务供应商。商品和服务的价格每 5-10 分钟更新一次,即 所有 5000 条记录都已更新。有必要快速比较供应商之间的商品/服务价格。选择将对应于每个产品/服务,包括加入,因为 某些产品的组件可能有自己的价格。此外,将在所有供应商之间比较所选产品/服务的价值。
提高性能的逻辑解决方案,我在内存表的使用中看到。其实我想听听有这方面经验的人的建议。实现这个的手段是什么?我应该使用 ORM 和 Hibernate,还是它们只会让所有事务变得更重?Embeded Sprin Boot 底座是否适合,还是使用第三方的更好?
帮助我理解。创建了一个简单的 Spring Boot 应用程序。我希望在应用程序启动时创建一个对象MyStr。现在在启动时出现错误(下面是堆栈跟踪)。据我了解,我没有指定 anywhere ContextLoaderListener,它允许您创建对象。我没有找到有关如何以及在何处添加侦听器的示例ContextLoaderListener。据我了解,一切都可以借助 type 注释来解决@WebListener,但无论我尝试多少,都没有任何反应。
@SpringBootApplication
@ComponentScan(value = "com.example")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
控制器:
@Controller
public class MyController {
private MyStr str;
@Autowired(required = true)
@Qualifier(value = "strQ")
public void setStr(MyStr str) {
this.str = str;
String a="";
}
}
链接类:
public class MyStr {
private String str;
public void setStr(String str) {
this.str = str;
}
}
弹簧配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.example"/>
<bean id="strQ" class="com.example.MyStr">
<qualifier value="strQ"/>
<property name="str" value="Mess"/>
</bean>
</beans>
错误:
2016-09-15 10:52:35.195 ERROR 12364 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyController': Unsatisfied dependency expressed through method 'setStr' parameter 0: No qualifying bean of type [com.example.MyStr] found for dependency [com.example.MyStr]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.MyStr] found for dependency [com.example.MyStr]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:648) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at com.example.DemoApplication.main(DemoApplication.java:12) [classes/:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.MyStr] found for dependency [com.example.MyStr]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 18 common frames omitted
我指的是控制器,它应该返回一个对象列表。对象将转换为 JSON 字符串。将对象转换为 JSON 字符串时,将调用所有对象 getter。结果,对象的所有数据都被返回。如何防止返回对象的某些字段,也许有特殊的注解?
@Controller
@MessageMapping("/v1.0")
public class MyController {
@MessageMapping("/getList")
@SendTo("/topic/List")
public Collection<MyObj> getList() throws Exception {
return this.MyObjService.getList();
}
}
实际上是未来对象的类:
public class MyObj {
private String name;
private String login;
public String getName() {
return name;
}
public String getLogin() {
return login;
}
}
我想禁用该字段的返回login。