Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
187f70b7
authored
Aug 25, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、解决可能出现的死锁问题(通过扩大线程池)
2、增加日志输出覆盖位置(当前只用于排错)
parent
63fe3fc0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
21 deletions
+28
-21
app/build.gradle
+3
-3
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+3
-0
app/src/main/java/com/bgycc/smartcanteen/executor/DefaultTaskExecutor.java
+17
-13
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
+4
-4
daemon/build.gradle
+1
-1
No files found.
app/build.gradle
View file @
187f70b7
...
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
...
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
android
{
android
{
compileSdkVersion
30
compileSdkVersion
30
buildToolsVersion
"30.0.
1
"
buildToolsVersion
"30.0.
2
"
defaultConfig
{
defaultConfig
{
applicationId
"com.bgycc.smartcanteen"
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
22
minSdkVersion
22
targetSdkVersion
30
targetSdkVersion
30
versionCode
14
3
versionCode
14
4
versionName
"1.4.
3
"
versionName
"1.4.
4
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
ndk
{
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
187f70b7
...
@@ -141,6 +141,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -141,6 +141,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
});
});
payOnlineViewModel
.
getPayOnlineStateEvent
().
observe
(
this
,
event
->
{
payOnlineViewModel
.
getPayOnlineStateEvent
().
observe
(
this
,
event
->
{
LogUtils
.
i
(
TAG
,
"在线支付状态: "
+
event
);
switch
(
event
.
getState
())
{
switch
(
event
.
getState
())
{
case
PayOnlineState
.
IDLE
:
case
PayOnlineState
.
IDLE
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
...
@@ -167,6 +168,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -167,6 +168,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
});
});
payOfflineViewModel
.
getPayOfflineStateEvent
().
observe
(
this
,
event
->
{
payOfflineViewModel
.
getPayOfflineStateEvent
().
observe
(
this
,
event
->
{
LogUtils
.
i
(
TAG
,
"离线支付状态: "
+
event
);
switch
(
event
.
getState
())
{
switch
(
event
.
getState
())
{
case
PayOfflineState
.
MARK
:
case
PayOfflineState
.
MARK
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
...
@@ -185,6 +187,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -185,6 +187,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
});
});
qrCodeViewModel
.
getQRCodeStateEvent
().
observe
(
this
,
event
->
{
qrCodeViewModel
.
getQRCodeStateEvent
().
observe
(
this
,
event
->
{
LogUtils
.
i
(
TAG
,
"扫码状态: "
+
event
);
switch
(
event
.
getState
())
{
switch
(
event
.
getState
())
{
case
QRCodeState
.
IDLE
:
case
QRCodeState
.
IDLE
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
...
...
app/src/main/java/com/bgycc/smartcanteen/executor/DefaultTaskExecutor.java
View file @
187f70b7
...
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
...
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledExecutorService
;
...
@@ -18,20 +19,21 @@ import java.util.concurrent.TimeUnit;
...
@@ -18,20 +19,21 @@ import java.util.concurrent.TimeUnit;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
public
class
DefaultTaskExecutor
extends
TaskExecutor
{
public
class
DefaultTaskExecutor
extends
TaskExecutor
{
private
final
Object
mLock
=
new
Object
();
private
final
ScheduledExecutorService
mThread
=
Executors
.
newScheduledThreadPool
(
6
,
new
ThreadFactory
()
{
private
static
final
String
THREAD_NAME_STEM
=
"SmartCanteen_Thread_%d"
;
private
static
final
String
THREAD_NAME_STEM
=
"SmartCanteen_Thread_%d"
;
private
final
Object
mLock
=
new
Object
();
private
final
AtomicInteger
mThreadId
=
new
AtomicInteger
(
0
);
private
final
AtomicInteger
mThreadId
=
new
AtomicInteger
(
0
);
@Override
private
final
ScheduledExecutorService
mScheduledThread
=
Executors
.
newScheduledThreadPool
(
10
,
r
->
{
public
Thread
newThread
(
@NotNull
Runnable
r
)
{
Thread
t
=
new
Thread
(
r
);
t
.
setName
(
String
.
format
(
Locale
.
CHINA
,
THREAD_NAME_STEM
,
mThreadId
.
getAndIncrement
()));
return
t
;
});
private
final
ExecutorService
mCacheThread
=
Executors
.
newCachedThreadPool
(
r
->
{
Thread
t
=
new
Thread
(
r
);
Thread
t
=
new
Thread
(
r
);
t
.
setName
(
String
.
format
(
Locale
.
CHINA
,
THREAD_NAME_STEM
,
mThreadId
.
getAndIncrement
()));
t
.
setName
(
String
.
format
(
Locale
.
CHINA
,
THREAD_NAME_STEM
,
mThreadId
.
getAndIncrement
()));
return
t
;
return
t
;
}
});
});
@Nullable
@Nullable
...
@@ -39,27 +41,27 @@ public class DefaultTaskExecutor extends TaskExecutor {
...
@@ -39,27 +41,27 @@ public class DefaultTaskExecutor extends TaskExecutor {
@Override
@Override
public
void
executeOnDiskIO
(
@NotNull
Runnable
runnable
)
{
public
void
executeOnDiskIO
(
@NotNull
Runnable
runnable
)
{
mThread
.
execute
(
runnable
);
m
Cache
Thread
.
execute
(
runnable
);
}
}
@Override
@Override
public
<
T
>
Future
<
T
>
submit
(
Callable
<
T
>
callable
)
{
public
<
T
>
Future
<
T
>
submit
(
Callable
<
T
>
callable
)
{
return
mThread
.
submit
(
callable
);
return
m
Cache
Thread
.
submit
(
callable
);
}
}
@Override
@Override
public
<
T
>
Future
<
T
>
submit
(
Runnable
runnable
,
T
result
)
{
public
<
T
>
Future
<
T
>
submit
(
Runnable
runnable
,
T
result
)
{
return
mThread
.
submit
(
runnable
,
result
);
return
m
Cache
Thread
.
submit
(
runnable
,
result
);
}
}
@Override
@Override
public
ScheduledFuture
<?>
schedule
(
Runnable
command
,
long
delay
,
TimeUnit
unit
)
{
public
ScheduledFuture
<?>
schedule
(
Runnable
command
,
long
delay
,
TimeUnit
unit
)
{
return
mThread
.
schedule
(
command
,
delay
,
unit
);
return
m
Scheduled
Thread
.
schedule
(
command
,
delay
,
unit
);
}
}
@Override
@Override
public
ScheduledFuture
<?>
scheduleAtFixedRate
(
Runnable
command
,
long
initialDelay
,
long
period
,
TimeUnit
unit
)
{
public
ScheduledFuture
<?>
scheduleAtFixedRate
(
Runnable
command
,
long
initialDelay
,
long
period
,
TimeUnit
unit
)
{
return
mThread
.
scheduleAtFixedRate
(
command
,
initialDelay
,
period
,
unit
);
return
m
Scheduled
Thread
.
scheduleAtFixedRate
(
command
,
initialDelay
,
period
,
unit
);
}
}
@Override
@Override
...
@@ -81,6 +83,7 @@ public class DefaultTaskExecutor extends TaskExecutor {
...
@@ -81,6 +83,7 @@ public class DefaultTaskExecutor extends TaskExecutor {
@Override
@Override
public
void
quit
()
{
public
void
quit
()
{
mThread
.
shutdownNow
();
mCacheThread
.
shutdownNow
();
mScheduledThread
.
shutdownNow
();
}
}
}
}
\ No newline at end of file
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
View file @
187f70b7
...
@@ -68,11 +68,11 @@ public class QRCodeViewModel extends ViewModel {
...
@@ -68,11 +68,11 @@ public class QRCodeViewModel extends ViewModel {
public
void
scan
()
{
public
void
scan
()
{
if
(
scan
==
null
)
return
;
if
(
scan
==
null
)
return
;
if
(
scanFuture
==
null
||
scanFuture
.
isDone
())
{
if
(
scanFuture
!=
null
)
{
scanFuture
=
SCTaskExecutor
.
getInstance
().
schedule
(
scanRunnable
,
DELAY
,
TimeUnit
.
MILLISECONDS
);
scanFuture
.
cancel
(
true
);
}
else
{
scanFuture
=
null
;
LogUtils
.
w
(
TAG
,
"当前已有扫码任务"
);
}
}
scanFuture
=
SCTaskExecutor
.
getInstance
().
schedule
(
scanRunnable
,
DELAY
,
TimeUnit
.
MILLISECONDS
);
}
}
private
Runnable
scanRunnable
=
()
->
{
private
Runnable
scanRunnable
=
()
->
{
...
...
daemon/build.gradle
View file @
187f70b7
...
@@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
...
@@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
def
signed
=
"Daemon.apk"
def
signed
=
"Daemon.apk"
android
{
android
{
compileSdkVersion
30
compileSdkVersion
30
buildToolsVersion
"30.0.
1
"
buildToolsVersion
"30.0.
2
"
defaultConfig
{
defaultConfig
{
applicationId
"com.bgycc.smartcanteen.daemon"
applicationId
"com.bgycc.smartcanteen.daemon"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment