某种方法myMethod调用多个并行执行并等待其终止。
这些并行执行可以例外完成。因此myMethod获得一个例外列表。
我想将异常列表作为根本原因进行传递,但根本原因可能只是单个异常。当然,我可以创建自己的异常来实现所需的功能,但是我想知道Java,Spring或Spring Batch是否具有类似这样的功能。
现在我有使用ms sql server的spring-boot应用程序.我们使用flyway fr迁移.
我想为测试添加额外的配置文件.我想从实体类生成表.并且不要使用飞路.
我试过smth在application.yaml中这样写
spring:
profiles: test
jpa:
generate-ddl: true
hibernate:
datasource:
url: jdbc:h2:mem:test_db;MODE=MSSQLServer
username: sa
password:
Run Code Online (Sandbox Code Playgroud)
但无论如何,flyway开始了
我使用maven来构建我的项目.
我有以下配置:
D:\ freelance\polyndrom> mvn -verion Apache Maven 3.2.3(33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0 + 04:00)Maven home:C:\ Program Files\apache\apache-maven-3.2. 3 Java版本:1.8.0_25,供应商:Oracle Corporation Java home:C:\ Program Files\Java\jdk1.8.0_25\jre默认语言环境:ru_RU,平台编码:Cp1251操作系统名称:"windows 7",版本:"6.1 ",arch:"amd64",家庭:"dos"
但是当我编译项目时,我看到以下错误:
lambda expressions are not supported in -source 1.5
Run Code Online (Sandbox Code Playgroud)
我很困惑 - 我看到我使用java 8.
pom.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>polyndrom</groupId>
<artifactId>polyndrom</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.peterservice.polyndrom.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud) 这是地图
@Autowired
private Map<String, ISendableConverter> converters;
Run Code Online (Sandbox Code Playgroud)
和 ISendableConverter
public interface ISendableConverter {
ISendableMsg convert(BaseMessage baseMessage);
String getType();
}
Run Code Online (Sandbox Code Playgroud)
有几个类实现 ISendableConverter
我想converters通过使用spring Autowried 将它们注入变量.
类的实例作为值,方法的结果@Autowried作为键.
像这个
@Component
public class SendableVoiceMsgConverter implements ISendableConverter {
@Override
public ISendableMsg convert(BaseMessage baseMessage) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getType() {
return "VOICE";
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?如何?
我的网站上有视频倒带的问题.
我找出了http标题的问题.
我当前的控制器方法返回视频:
@RequestMapping(method = RequestMethod.GET, value = "/testVideo")
@ResponseBody
public FileSystemResource testVideo(Principal principal) throws IOException {
return new FileSystemResource(new File("D:\\oceans.mp4"));
}
Run Code Online (Sandbox Code Playgroud)
如何用字节范围支持重写以下代码?
我见过以下示例http://balusc.blogspot.in/2009/02/fileservlet-supporting-resume-and.html
但是这段代码看起来很难,我无法理解.我希望在春天mvc存在方式更简单.
我有以下项目结构:
以下源代码:
SocialApplication.class:
@SpringBootApplication
@RestController
@EnableOAuth2Client
@EnableAuthorizationServer
@Order(200)
public class SocialApplication extends WebSecurityConfigurerAdapter {
@Autowired
OAuth2ClientContext oauth2ClientContext;
@RequestMapping({ "/user", "/me" })
public Map<String, String> user(Principal principal) {
Map<String, String> map = new LinkedHashMap<>();
map.put("name", principal.getName());
return map;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll().anyRequest()
.authenticated().and().exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
.logoutSuccessUrl("/").permitAll().and().csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and()
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
// @formatter:on
}
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception …Run Code Online (Sandbox Code Playgroud) 我一直在调查java.lang.Long类源代码.
考虑一下:
public final class Long extends Number implements Comparable<Long> {
....
private final long value;
....
public long longValue() {
return (long)value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
什么是投理由long来long?
为什么不在这种情况下将序列化(?)重新归类为Number类?
PS1 源代码链接
我有这些可能的解释:
PS2
我的java版本 - 1.7.0_45-b18
PS3 仅供参考:
Integer:
public final class Integer extends Number implements Comparable<Integer> {
....
private final int value;
....
public int intValue() {
return value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
Short:
public final class Short …Run Code Online (Sandbox Code Playgroud) 当我想要注销时,我调用此代码:
request.getSession().invalidate();
SecurityContextHolder.getContext().setAuthentication(null);
Run Code Online (Sandbox Code Playgroud)
但在它之后(在使用旧的oauth令牌的下一个请求中)我调用
SecurityContextHolder.getContext().getAuthentication();
我在那里看到我的老用户
怎么解决?
我在项目中面对以下代码:
synchronized (Thread.currentThread()){
//some code
}
Run Code Online (Sandbox Code Playgroud)
我不明白使用synchronized的原因currentThread.
两者之间有什么区别吗?
synchronized (Thread.currentThread()){
//some code
}
Run Code Online (Sandbox Code Playgroud)
只是
//some code
Run Code Online (Sandbox Code Playgroud)
你能提供一个显示差异的例子吗?
更详细的代码如下:
synchronized (Thread.currentThread()) {
Thread.currentThread().wait(timeInterval);
}
Run Code Online (Sandbox Code Playgroud)
看起来就像Thread.sleep(timeInterval).这是真的吗?
java concurrency multithreading synchronization thread-safety
我在项目中使用spring security.
我有更改登录功能.为实现这一目标,我使用以下代码
Authentication authentication = ...
SecurityContextHolder.getContext().setAuthentication(authentication);
Run Code Online (Sandbox Code Playgroud)
但是现在我正在详细讨论这段代码并且看到认证字段不是volatile因此不能保证可见性:
public class SecurityContextImpl implements SecurityContext {
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
// ~ Instance fields
// ================================================================================================
private Authentication authentication;
Run Code Online (Sandbox Code Playgroud)
我应该用自己的同步来包装我的代码以实现可见性吗?
在单个会话中接收并发请求的应用程序中,将在线程之间共享相同的SecurityContext实例.即使正在使用ThreadLocal,它也是从HttpSession为每个线程检索的相同实例.如果您希望临时更改运行线程的上下文,则会产生影响.如果您只使用SecurityContextHolder.getContext(),并对返回的上下文对象调用setAuthentication(anAuthentication),则Authentication对象将在共享同一SecurityContext实例的所有并发线程中更改.您可以自定义SecurityContextPersistenceFilter的行为,为每个请求创建一个全新的SecurityContext,防止一个线程中的更改影响另一个线程.或者,您可以在临时更改上下文的位置创建新实例.SecurityContextHolder.createEmptyContext()方法始终返回新的上下文实例.
但我不明白春天如何保证能见度.刚写过会话中的每个线程都会看到变化.但没有答案有多快?更重要的是 - 没有解释可见性机制
java multithreading visibility spring-security thread-safety
java ×10
spring ×5
oauth-2.0 ×2
autowired ×1
concurrency ×1
exception ×1
flyway ×1
http ×1
lambda ×1
long-integer ×1
maven ×1
numbers ×1
spring-batch ×1
spring-boot ×1
spring-mvc ×1
visibility ×1