我想编写一个后台作业(EJB 3.1),它每分钟执行一次.为此,我使用以下注释:
@Schedule(minute = "*/1", hour = "*")
Run Code Online (Sandbox Code Playgroud)
这工作正常.
但是,有时候这项工作可能需要一分多钟.在这种情况下,计时器仍然被触发,导致线程问题.
如果当前执行没有完成,是否可以终止调度程序?
我使用以下配置对我的Web应用程序进行了有效的JWT身份验证:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(
(req, rsp, e) -> p.sendError(HttpServletResponse.SC_UNAUTHORIZED))
.and()
.addFilter(new UsernamePasswordAuthenticationFilter(authenticationManager(),
jwtConfig))
.addFilterAfter(new JwtTokenAuthenticationFilter(jwtConfig),
UsernamePasswordAuthenticationFilter.class)
.authorizeRequests()
.antMatchers(HttpMethod.POST, jwtConfig.getUri()).permitAll()
.anyRequest().authenticated();
}
Run Code Online (Sandbox Code Playgroud)
因为SessionCreationPolicy.STATELESS我期待Spring不会创建会话本身.但是,如果我访问任何其他资源/login,我仍然会在响应标头中看到以下条目:
set-cookie: JSESSIONID=...; Path=/; HttpOnly
Run Code Online (Sandbox Code Playgroud)
有人可以解释它来自哪里(也许不是来自Spring),如果它仍然来自Spring,那么需要改变什么?
编辑:
在我的控制器中进行测试,会话仍按照上述令牌所示进行注入.我仍然不知道这是从哪里来的.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void create(HttpSession session) {
if (session != null) {
System.out.println("Session is existing"); // executes
}
}
Run Code Online (Sandbox Code Playgroud) 我需要以代码中的关系连接到 postgreSQL 数据库。问题在于表“b”中的数据库“id”是“bigint”,表“a”中的“b_id”是“整数”,prod db 不在我的控制范围内,所以我无法更改它。
“a”中的“b_id”未定义为外键,这可能就是 postgre 允许这样做的原因。
正如预期的那样,hibernate 抛出“找到 [int4 (Types#INTEGER)],但期待 [integer (Types#BIGINT)]”
如果我通过休眠创建表,它会按预期将表“a”中的“b_id”定义为“bigint”
在不更改数据库类型的情况下验证模式的最佳方法是什么?
@Entity
@Table(name = "a")
public class A {
@ManyToOne
@JoinColumn(name = "b_id")
@NotNull
private B bId;
...
}
@Entity
@Table(name = "b")
public class B {
@Id
private Long id;
...
}
Run Code Online (Sandbox Code Playgroud) 基于值的类具有以下特性
是最终的且不可变的(尽管可能包含对可变对象的引用)。
因此,如果您知道对象仅包含不可变的实例,则可以预先计算hashCode实例的。使用Map或Set操作时,这可以加快访问速度。
hashCode从Instant基于值的类from 的实现看,开发人员为什么决定反对这种模式?hashCode与需要一遍又一遍地进行计算相比,预计算的性能损失是否会更加严重?
// copied from Instant#hashCode
@Override
public int hashCode() {
return ((int) (seconds ^ (seconds >>> 32))) + 51 * nanos;
}
Run Code Online (Sandbox Code Playgroud)
那么,在什么条件下预先计算是hashCode合理的呢?
给定根路由模块
const appRoutes: Routes = [
{
path: '',
component: HomeComponent,
children: [
{
path: 'users',
loadChildren: './pages/users/users.module#UsersModule'
}
]
},
{path: '', redirectTo: '', pathMatch: 'full'},
{path: '**', redirectTo: '/login'}
];
export const appRouting: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
和用户路由模块
const usersRoutes: Routes = [
{
path: '', component: UsersComponent,
children: [
{path: 'admittances', component: AdmittancesComponent},
{path: 'admittance/:id', component: AdmittanceDetailComponent}
]
}
];
export const usersRouting: ModuleWithProviders = RouterModule.forChild(usersRoutes);
Run Code Online (Sandbox Code Playgroud)
我想从导航AdmittancesComponent到AdmittanceDetailComponent。
但是,而不是使用
this._router.navigate(['admittance', id]); // ERROR
Run Code Online (Sandbox Code Playgroud)
我宁愿使用
this._router.navigate(['users/admittance', …Run Code Online (Sandbox Code Playgroud) 这是原始代码:
Set<StatuteType> statuteTypes = registration.getStudent().getStudentStatutesSet()
.stream()
.map(StudentStatute_Base::getType)
.collect(Collectors.toSet());
Run Code Online (Sandbox Code Playgroud)
我想将所有内容都包装在 Optional 中以避免空指针和所有内容。如果学生不存在或法规集不存在。
我拥有的:
Set<StatuteType> statuteTypes = Optional.of(registration)
.map(Registration_Base::getStudent)
.map(student -> student.getStudentStatutesSet())
.flatMap(Collection::stream)
.map(StudentStatute_Base::getType)
.collect(Collectors.toSet())
.orElse(null);
Run Code Online (Sandbox Code Playgroud)
这样的事情有可能吗?我想避免在这个链中检查空值,如果有空值,也只返回一个简单的空值,而不是得到一个异常。
通常,我认为合乎逻辑的是使用此处描述的flatMap,但在这种情况下似乎不正确,因为 Optional flatmap 返回一个 Optional。